1 /* $Id: l3dss1.c,v 2.32.2.3 2004/01/13 14:31:25 keil Exp $
3 * EURO/DSS1 D-channel protocol
5 * German 1TR6 D-channel protocol
8 * based on the teles driver from Jan den Ouden
9 * Copyright by Karsten Keil <keil@isdn4linux.de>
11 * This software may be used and distributed according to the terms
12 * of the GNU General Public License, incorporated herein by reference.
14 * For changes and modifications please read
15 * Documentation/isdn/HiSax.cert
17 * Thanks to Jan den Ouden
25 #include <linux/ctype.h>
26 #include <linux/config.h>
28 extern char *HiSax_getrev(const char *revision);
29 static const char *dss1_revision = "$Revision: 2.32.2.3 $";
31 #define EXT_BEARER_CAPS 1
33 #define MsgHead(ptr, cref, mty) \
44 /**********************************************/
45 /* get a new invoke id for remote operations. */
46 /* Only a return value != 0 is valid */
47 /**********************************************/
48 static unsigned char new_invoke_id(struct PStack *p)
53 i = 32; /* maximum search depth */
55 retval = p->prot.dss1.last_invoke_id + 1; /* try new id */
56 while ((i) && (p->prot.dss1.invoke_used[retval >> 3] == 0xFF)) {
57 p->prot.dss1.last_invoke_id = (retval & 0xF8) + 8;
61 while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7)))
65 p->prot.dss1.last_invoke_id = retval;
66 p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7));
70 /*************************/
71 /* free a used invoke id */
72 /*************************/
73 static void free_invoke_id(struct PStack *p, unsigned char id)
76 if (!id) return; /* 0 = invalid value */
78 p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7));
79 } /* free_invoke_id */
82 /**********************************************************/
83 /* create a new l3 process and fill in dss1 specific data */
84 /**********************************************************/
85 static struct l3_process
86 *dss1_new_l3_process(struct PStack *st, int cr)
87 { struct l3_process *proc;
89 if (!(proc = new_l3_process(st, cr)))
92 proc->prot.dss1.invoke_id = 0;
93 proc->prot.dss1.remote_operation = 0;
94 proc->prot.dss1.uus1_data[0] = '\0';
97 } /* dss1_new_l3_process */
99 /************************************************/
100 /* free a l3 process and all dss1 specific data */
101 /************************************************/
103 dss1_release_l3_process(struct l3_process *p)
105 free_invoke_id(p->st,p->prot.dss1.invoke_id);
106 release_l3_process(p);
107 } /* dss1_release_l3_process */
109 /********************************************************/
110 /* search a process with invoke id id and dummy callref */
111 /********************************************************/
112 static struct l3_process *
113 l3dss1_search_dummy_proc(struct PStack *st, int id)
114 { struct l3_process *pc = st->l3.proc; /* start of processes */
116 if (!id) return(NULL);
119 { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id))
124 } /* l3dss1_search_dummy_proc */
126 /*******************************************************************/
127 /* called when a facility message with a dummy callref is received */
128 /* and a return result is delivered. id specifies the invoke id. */
129 /*******************************************************************/
131 l3dss1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
133 struct IsdnCardState *cs;
134 struct l3_process *pc = NULL;
136 if ((pc = l3dss1_search_dummy_proc(st, id)))
137 { L3DelTimer(&pc->timer); /* remove timer */
139 cs = pc->st->l1.hardware;
140 ic.driver = cs->myid;
141 ic.command = ISDN_STAT_PROT;
142 ic.arg = DSS1_STAT_INVOKE_RES;
143 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
144 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
145 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
146 ic.parm.dss1_io.timeout= 0;
147 ic.parm.dss1_io.datalen = nlen;
148 ic.parm.dss1_io.data = p;
149 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
150 pc->prot.dss1.invoke_id = 0; /* reset id */
152 cs->iif.statcallb(&ic);
153 dss1_release_l3_process(pc);
156 l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
157 } /* l3dss1_dummy_return_result */
159 /*******************************************************************/
160 /* called when a facility message with a dummy callref is received */
161 /* and a return error is delivered. id specifies the invoke id. */
162 /*******************************************************************/
164 l3dss1_dummy_error_return(struct PStack *st, int id, ulong error)
166 struct IsdnCardState *cs;
167 struct l3_process *pc = NULL;
169 if ((pc = l3dss1_search_dummy_proc(st, id)))
170 { L3DelTimer(&pc->timer); /* remove timer */
172 cs = pc->st->l1.hardware;
173 ic.driver = cs->myid;
174 ic.command = ISDN_STAT_PROT;
175 ic.arg = DSS1_STAT_INVOKE_ERR;
176 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
177 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
178 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
179 ic.parm.dss1_io.timeout= error;
180 ic.parm.dss1_io.datalen = 0;
181 ic.parm.dss1_io.data = NULL;
182 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
183 pc->prot.dss1.invoke_id = 0; /* reset id */
185 cs->iif.statcallb(&ic);
186 dss1_release_l3_process(pc);
189 l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
190 } /* l3dss1_error_return */
192 /*******************************************************************/
193 /* called when a facility message with a dummy callref is received */
194 /* and a invoke is delivered. id specifies the invoke id. */
195 /*******************************************************************/
197 l3dss1_dummy_invoke(struct PStack *st, int cr, int id,
198 int ident, u_char *p, u_char nlen)
200 struct IsdnCardState *cs;
202 l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
203 (cr == -1) ? "local" : "broadcast",id,ident,nlen);
204 if (cr >= -1) return; /* ignore local data */
206 cs = st->l1.hardware;
207 ic.driver = cs->myid;
208 ic.command = ISDN_STAT_PROT;
209 ic.arg = DSS1_STAT_INVOKE_BRD;
210 ic.parm.dss1_io.hl_id = id;
211 ic.parm.dss1_io.ll_id = 0;
212 ic.parm.dss1_io.proc = ident;
213 ic.parm.dss1_io.timeout= 0;
214 ic.parm.dss1_io.datalen = nlen;
215 ic.parm.dss1_io.data = p;
217 cs->iif.statcallb(&ic);
218 } /* l3dss1_dummy_invoke */
221 l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
225 unsigned char nlen = 0, ilen, cp_tag;
230 st = pc->st; /* valid Stack */
232 if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
237 l3_debug(st, "qd_len == 0");
240 if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
241 l3_debug(st, "supplementary service != 0x11");
244 while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
249 l3_debug(st, "qd_len < 2");
254 if ((*p & 0xE0) != 0xA0) { /* class and form */
255 l3_debug(st, "class and form != 0xA0");
259 cp_tag = *p & 0x1F; /* remember tag value */
264 { l3_debug(st, "qd_len < 1");
268 { /* length format indefinite or limited */
269 nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
270 if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
272 { l3_debug(st, "length format error or not implemented");
276 { nlen = *p++; /* complete length */
280 { qd_len -= 2; /* trailing null bytes */
281 if ((*(p+qd_len)) || (*(p+qd_len+1)))
282 { l3_debug(st,"length format indefinite error");
293 { l3_debug(st, "qd_len < nlen");
299 { l3_debug(st, "nlen < 2");
303 { /* invoke identifier tag */
304 l3_debug(st, "invoke identifier tag !=0x02");
310 { /* length format */
311 l3_debug(st, "invoke id length format 2");
316 if (ilen > nlen || ilen == 0)
317 { l3_debug(st, "ilen > nlen || ilen == 0");
323 { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
327 switch (cp_tag) { /* component tag */
330 l3_debug(st, "nlen < 2 22");
333 if (*p != 0x02) { /* operation value */
334 l3_debug(st, "operation value !=0x02");
341 if (ilen > nlen || ilen == 0) {
342 l3_debug(st, "ilen > nlen || ilen == 0 22");
348 ident = (ident << 8) | (*p++ & 0xFF);
353 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
359 #define FOO1(s,a,b) \
362 if(nlen < ilen+2) { \
363 l3_debug(st, "FOO1 nlen < ilen+2"); \
367 if((*p & 0xFF) == (a)) { \
377 case 0x22: /* during */
378 FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( {
380 nlen = (nlen)?nlen:0; /* Make gcc happy */
382 ident = (ident << 8) | *p++;
385 if (ident > pc->para.chargeinfo) {
386 pc->para.chargeinfo = ident;
387 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
389 if (st->l3.debug & L3_DEB_CHARGE) {
391 l3_debug(st, "charging info during %d", pc->para.chargeinfo);
394 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
400 case 0x24: /* final */
401 FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( {
403 nlen = (nlen)?nlen:0; /* Make gcc happy */
405 ident = (ident << 8) | *p++;
408 if (ident > pc->para.chargeinfo) {
409 pc->para.chargeinfo = ident;
410 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
412 if (st->l3.debug & L3_DEB_CHARGE) {
413 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
419 l3_debug(st, "invoke break invalid ident %02x",ident);
425 #else /* not HISAX_DE_AOC */
426 l3_debug(st, "invoke break");
427 #endif /* not HISAX_DE_AOC */
429 case 2: /* return result */
430 /* if no process available handle separately */
433 l3dss1_dummy_return_result(st, id, p, nlen);
436 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
437 { /* Diversion successful */
438 free_invoke_id(st,pc->prot.dss1.invoke_id);
439 pc->prot.dss1.remote_result = 0; /* success */
440 pc->prot.dss1.invoke_id = 0;
441 pc->redir_result = pc->prot.dss1.remote_result;
442 st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
444 l3_debug(st,"return error unknown identifier");
446 case 3: /* return error */
449 { l3_debug(st, "return error nlen < 2");
454 l3_debug(st, "invoke error tag !=0x02");
460 { /* length format */
461 l3_debug(st, "invoke return errlen > 4 ");
466 if (ilen > nlen || ilen == 0)
467 { l3_debug(st, "error return ilen > nlen || ilen == 0");
472 { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
475 /* if no process available handle separately */
478 l3dss1_dummy_error_return(st, id, err_ret);
481 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
482 { /* Deflection error */
483 free_invoke_id(st,pc->prot.dss1.invoke_id);
484 pc->prot.dss1.remote_result = err_ret; /* result */
485 pc->prot.dss1.invoke_id = 0;
486 pc->redir_result = pc->prot.dss1.remote_result;
487 st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
488 } /* Deflection error */
490 l3_debug(st,"return result unknown identifier");
493 l3_debug(st, "facility default break tag=0x%02x",cp_tag);
499 l3dss1_message(struct l3_process *pc, u_char mt)
504 if (!(skb = l3_alloc_skb(4)))
507 MsgHead(p, pc->callref, mt);
508 l3_msg(pc->st, DL_DATA | REQUEST, skb);
512 l3dss1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
519 MsgHead(p, pc->callref, mt);
526 if (!(skb = l3_alloc_skb(l)))
528 memcpy(skb_put(skb, l), tmp, l);
529 l3_msg(pc->st, DL_DATA | REQUEST, skb);
533 l3dss1_status_send(struct l3_process *pc, u_char pr, void *arg)
540 MsgHead(p, pc->callref, MT_STATUS);
545 *p++ = pc->para.cause | 0x80;
547 *p++ = IE_CALL_STATE;
549 *p++ = pc->state & 0x3f;
552 if (!(skb = l3_alloc_skb(l)))
554 memcpy(skb_put(skb, l), tmp, l);
555 l3_msg(pc->st, DL_DATA | REQUEST, skb);
559 l3dss1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
561 /* This routine is called if here was no SETUP made (checks in dss1up and in
562 * l3dss1_setup) and a RELEASE_COMPLETE have to be sent with an error code
563 * MT_STATUS_ENQUIRE in the NULL state is handled too
570 switch (pc->para.cause) {
571 case 81: /* invalid callreference */
572 case 88: /* incomp destination */
573 case 96: /* mandory IE missing */
574 case 100: /* invalid IE contents */
575 case 101: /* incompatible Callstate */
576 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
580 *p++ = pc->para.cause | 0x80;
583 printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n",
588 if (!(skb = l3_alloc_skb(l)))
590 memcpy(skb_put(skb, l), tmp, l);
591 l3_msg(pc->st, DL_DATA | REQUEST, skb);
592 dss1_release_l3_process(pc);
595 static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
596 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
598 static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
599 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
600 static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
601 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
602 IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
603 static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
604 static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
605 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
606 static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
608 static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
609 static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
610 IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
611 static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
612 IE_SIGNAL, IE_USER_USER, -1};
613 /* a RELEASE_COMPLETE with errors don't require special actions
614 static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
616 static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
618 static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
619 static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
620 IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
621 IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
622 IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
623 IE_LLC, IE_HLC, IE_USER_USER, -1};
624 static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
625 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
626 static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
627 IE_MANDATORY, IE_DISPLAY, -1};
628 static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
629 static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
630 static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
632 * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
633 * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
634 * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
635 * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
638 static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
639 static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
640 static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
648 struct ie_len max_ie_len[] = {
666 {IE_PACK_BINPARA, 3},
667 {IE_PACK_WINSIZE, 4},
672 {IE_CALLING_SUB, 23},
685 getmax_ie_len(u_char ie) {
687 while (max_ie_len[i].ie != -1) {
688 if (max_ie_len[i].ie == ie)
689 return(max_ie_len[i].len);
696 ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
699 while (*checklist != -1) {
700 if ((*checklist & 0xff) == ie) {
713 check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
718 int l, newpos, oldpos;
719 int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
721 u_char old_codeset = 0;
731 while ((p - skb->data) < skb->len) {
732 if ((*p & 0xf0) == 0x90) { /* shift codeset */
733 old_codeset = codeset;
739 if (pc->debug & L3_DEB_CHECK)
740 l3_debug(pc->st, "check IE shift%scodeset %d->%d",
741 codelock ? " locking ": " ", old_codeset, codeset);
745 if (!codeset) { /* only codeset 0 */
746 if ((newpos = ie_in_set(pc, *p, cl))) {
754 if (ie_in_set(pc, *p, comp_required))
768 if (!codeset && (l > getmax_ie_len(ie)))
771 if (pc->debug & L3_DEB_CHECK)
772 l3_debug(pc->st, "check IE shift back codeset %d->%d",
773 codeset, old_codeset);
774 codeset = old_codeset;
778 if (err_compr | err_ureg | err_len | err_seq) {
779 if (pc->debug & L3_DEB_CHECK)
780 l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
781 mt, err_compr, err_ureg, err_len, err_seq);
783 return(ERR_IE_COMPREHENSION);
785 return(ERR_IE_UNRECOGNIZED);
787 return(ERR_IE_LENGTH);
789 return(ERR_IE_SEQUENCE);
794 /* verify if a message type exists and contain no IE error */
796 l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
800 case MT_CALL_PROCEEDING:
802 case MT_CONNECT_ACKNOWLEDGE:
809 case MT_RELEASE_COMPLETE:
811 case MT_SETUP_ACKNOWLEDGE:
812 case MT_RESUME_ACKNOWLEDGE:
813 case MT_RESUME_REJECT:
814 case MT_SUSPEND_ACKNOWLEDGE:
815 case MT_SUSPEND_REJECT:
816 case MT_USER_INFORMATION:
818 case MT_RESTART_ACKNOWLEDGE:
819 case MT_CONGESTION_CONTROL:
821 case MT_STATUS_ENQUIRY:
822 if (pc->debug & L3_DEB_CHECK)
823 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) OK", mt);
825 case MT_RESUME: /* RESUME only in user->net */
826 case MT_SUSPEND: /* SUSPEND only in user->net */
828 if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
829 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt);
831 l3dss1_status_send(pc, 0, NULL);
838 l3dss1_std_ie_err(struct l3_process *pc, int ret) {
840 if (pc->debug & L3_DEB_CHECK)
841 l3_debug(pc->st, "check_infoelements ret %d", ret);
845 case ERR_IE_COMPREHENSION:
847 l3dss1_status_send(pc, 0, NULL);
849 case ERR_IE_UNRECOGNIZED:
851 l3dss1_status_send(pc, 0, NULL);
854 pc->para.cause = 100;
855 l3dss1_status_send(pc, 0, NULL);
857 case ERR_IE_SEQUENCE:
864 l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
868 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
870 if (*p != 1) { /* len for BRI = 1 */
871 if (pc->debug & L3_DEB_WARN)
872 l3_debug(pc->st, "wrong chid len %d", *p);
876 if (*p & 0x60) { /* only base rate interface */
877 if (pc->debug & L3_DEB_WARN)
878 l3_debug(pc->st, "wrong chid %x", *p);
887 l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
894 if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
905 if (l && !(pc->para.loc & 0x80)) {
907 p++; /* skip recommendation */
910 pc->para.cause = *p++;
912 if (!(pc->para.cause & 0x80))
917 pc->para.diag[i++] = *p++;
926 l3dss1_msg_with_uus(struct l3_process *pc, u_char cmd)
933 MsgHead(p, pc->callref, cmd);
935 if (pc->prot.dss1.uus1_data[0])
936 { *p++ = IE_USER_USER; /* UUS info element */
937 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
938 *p++ = 0x04; /* IA5 chars */
939 strcpy(p,pc->prot.dss1.uus1_data);
940 p += strlen(pc->prot.dss1.uus1_data);
941 pc->prot.dss1.uus1_data[0] = '\0';
945 if (!(skb = l3_alloc_skb(l)))
947 memcpy(skb_put(skb, l), tmp, l);
948 l3_msg(pc->st, DL_DATA | REQUEST, skb);
949 } /* l3dss1_msg_with_uus */
952 l3dss1_release_req(struct l3_process *pc, u_char pr, void *arg)
956 if (!pc->prot.dss1.uus1_data[0])
957 l3dss1_message(pc, MT_RELEASE);
959 l3dss1_msg_with_uus(pc, MT_RELEASE);
960 L3AddTimer(&pc->timer, T308, CC_T308_1);
964 l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
966 struct sk_buff *skb = arg;
969 if ((ret = l3dss1_get_cause(pc, skb))>0) {
970 if (pc->debug & L3_DEB_WARN)
971 l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
973 pc->para.cause = NO_CAUSE;
976 pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
977 dss1_release_l3_process(pc);
980 #ifdef EXT_BEARER_CAPS
983 EncodeASyncParams(u_char * p, u_char si2)
984 { // 7c 06 88 90 21 42 00 bb
987 p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
989 if (si2 & 32) // 7 data bits
996 if (si2 & 16) // 2 stop bits
1003 if (si2 & 8) // even parity
1010 switch (si2 & 0x07) {
1012 p[0] = 66; // 1200 bit/s
1016 p[0] = 88; // 1200/75 bit/s
1020 p[0] = 87; // 75/1200 bit/s
1024 p[0] = 67; // 2400 bit/s
1028 p[0] = 69; // 4800 bit/s
1032 p[0] = 72; // 9600 bit/s
1036 p[0] = 73; // 14400 bit/s
1040 p[0] = 75; // 19200 bit/s
1048 EncodeSyncParams(u_char si2, u_char ai)
1053 return ai + 2; // 1200 bit/s
1056 return ai + 24; // 1200/75 bit/s
1059 return ai + 23; // 75/1200 bit/s
1062 return ai + 3; // 2400 bit/s
1065 return ai + 5; // 4800 bit/s
1068 return ai + 8; // 9600 bit/s
1071 return ai + 9; // 14400 bit/s
1074 return ai + 11; // 19200 bit/s
1077 return ai + 14; // 48000 bit/s
1080 return ai + 15; // 56000 bit/s
1083 return ai + 40; // negotiate bit/s
1093 DecodeASyncParams(u_char si2, u_char * p)
1098 case 66: // 1200 bit/s
1100 break; // si2 don't change
1102 case 88: // 1200/75 bit/s
1106 case 87: // 75/1200 bit/s
1110 case 67: // 2400 bit/s
1114 case 69: // 4800 bit/s
1118 case 72: // 9600 bit/s
1122 case 73: // 14400 bit/s
1126 case 75: // 19200 bit/s
1133 if ((info & 16) && (!(info & 8))) // 7 data bits
1135 si2 += 32; // else 8 data bits
1137 if ((info & 96) == 96) // 2 stop bits
1139 si2 += 16; // else 1 stop bit
1141 if ((info & 2) && (!(info & 1))) // even parity
1143 si2 += 8; // else no parity
1150 DecodeSyncParams(u_char si2, u_char info)
1154 case 40: // bit/s negotiation failed ai := 165 not 175!
1157 case 15: // 56000 bit/s failed, ai := 0 not 169 !
1160 case 14: // 48000 bit/s
1163 case 11: // 19200 bit/s
1166 case 9: // 14400 bit/s
1169 case 8: // 9600 bit/s
1172 case 5: // 4800 bit/s
1175 case 3: // 2400 bit/s
1178 case 23: // 75/1200 bit/s
1181 case 24: // 1200/75 bit/s
1184 default: // 1200 bit/s
1191 DecodeSI2(struct sk_buff *skb)
1193 u_char *p; //, *pend=skb->data + skb->len;
1195 if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
1196 switch (p[4] & 0x0f) {
1198 if (p[1] == 0x04) // sync. Bitratenadaption
1200 return DecodeSyncParams(160, p[5]); // V.110/X.30
1202 else if (p[1] == 0x06) // async. Bitratenadaption
1204 return DecodeASyncParams(192, p); // V.110/X.30
1207 case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
1209 return DecodeSyncParams(176, p[5]); // V.120
1220 l3dss1_setup_req(struct l3_process *pc, u_char pr,
1223 struct sk_buff *skb;
1229 u_char screen = 0x80;
1236 MsgHead(p, pc->callref, MT_SETUP);
1238 teln = pc->para.setup.phone;
1239 #ifndef CONFIG_HISAX_NO_KEYPAD
1240 send_keypad = (strchr(teln,'*') || strchr(teln,'#')) ? 1 : 0;
1244 #ifndef CONFIG_HISAX_NO_SENDCOMPLETE
1246 *p++ = 0xa1; /* complete indicator */
1249 * Set Bearer Capability, Map info from 1TR6-convention to EDSS1
1251 switch (pc->para.setup.si1) {
1252 case 1: /* Telephony */
1254 *p++ = 0x3; /* Length */
1255 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1256 *p++ = 0x90; /* Circuit-Mode 64kbps */
1257 *p++ = 0xa3; /* A-Law Audio */
1259 case 5: /* Datatransmission 64k, BTX */
1260 case 7: /* Datatransmission 64k */
1263 *p++ = 0x2; /* Length */
1264 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1265 *p++ = 0x90; /* Circuit-Mode 64kbps */
1271 *p++ = strlen(teln);
1273 *p++ = (*teln++) & 0x7F;
1277 * What about info2? Mapping to High-Layer-Compatibility?
1279 if ((*teln) && (!send_keypad)) {
1280 /* parse number for special things */
1281 if (!isdigit(*teln)) {
1282 switch (0x5f & *teln) {
1301 if (pc->debug & L3_DEB_WARN)
1302 l3_debug(pc->st, "Wrong MSN Code");
1309 *p++ = IE_CHANNEL_ID;
1313 msn = pc->para.setup.eazmsn;
1324 *p++ = IE_CALLING_PN;
1325 *p++ = strlen(msn) + (screen ? 2 : 1);
1326 /* Classify as AnyPref. */
1328 *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
1331 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1333 *p++ = *msn++ & 0x7f;
1337 *p++ = IE_CALLING_SUB;
1338 *p++ = strlen(sub) + 2;
1339 *p++ = 0x80; /* NSAP coded */
1340 *p++ = 0x50; /* local IDI format */
1342 *p++ = *sub++ & 0x7f;
1355 *p++ = IE_CALLED_PN;
1356 *p++ = strlen(teln) + 1;
1357 /* Classify as AnyPref. */
1358 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1360 *p++ = *teln++ & 0x7f;
1364 *p++ = IE_CALLED_SUB;
1365 *p++ = strlen(sub) + 2;
1366 *p++ = 0x80; /* NSAP coded */
1367 *p++ = 0x50; /* local IDI format */
1369 *p++ = *sub++ & 0x7f;
1372 #ifdef EXT_BEARER_CAPS
1373 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1380 *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
1381 } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
1388 *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
1390 } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
1397 p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
1398 #ifndef CONFIG_HISAX_NO_LLC
1400 switch (pc->para.setup.si1) {
1401 case 1: /* Telephony */
1403 *p++ = 0x3; /* Length */
1404 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1405 *p++ = 0x90; /* Circuit-Mode 64kbps */
1406 *p++ = 0xa3; /* A-Law Audio */
1408 case 5: /* Datatransmission 64k, BTX */
1409 case 7: /* Datatransmission 64k */
1412 *p++ = 0x2; /* Length */
1413 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1414 *p++ = 0x90; /* Circuit-Mode 64kbps */
1421 if (!(skb = l3_alloc_skb(l)))
1423 memcpy(skb_put(skb, l), tmp, l);
1424 L3DelTimer(&pc->timer);
1425 L3AddTimer(&pc->timer, T303, CC_T303);
1427 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1431 l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg)
1433 struct sk_buff *skb = arg;
1436 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1437 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1438 if (pc->debug & L3_DEB_WARN)
1439 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1440 pc->para.cause = 100;
1441 l3dss1_status_send(pc, pr, NULL);
1444 pc->para.bchannel = id;
1445 } else if (1 == pc->state) {
1446 if (pc->debug & L3_DEB_WARN)
1447 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1449 pc->para.cause = 96;
1451 pc->para.cause = 100;
1452 l3dss1_status_send(pc, pr, NULL);
1455 /* Now we are on none mandatory IEs */
1456 ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
1457 if (ERR_IE_COMPREHENSION == ret) {
1458 l3dss1_std_ie_err(pc, ret);
1461 L3DelTimer(&pc->timer);
1463 L3AddTimer(&pc->timer, T310, CC_T310);
1464 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1465 l3dss1_std_ie_err(pc, ret);
1466 pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
1470 l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
1472 struct sk_buff *skb = arg;
1475 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1476 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1477 if (pc->debug & L3_DEB_WARN)
1478 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1479 pc->para.cause = 100;
1480 l3dss1_status_send(pc, pr, NULL);
1483 pc->para.bchannel = id;
1485 if (pc->debug & L3_DEB_WARN)
1486 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1488 pc->para.cause = 96;
1490 pc->para.cause = 100;
1491 l3dss1_status_send(pc, pr, NULL);
1494 /* Now we are on none mandatory IEs */
1495 ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
1496 if (ERR_IE_COMPREHENSION == ret) {
1497 l3dss1_std_ie_err(pc, ret);
1500 L3DelTimer(&pc->timer);
1502 L3AddTimer(&pc->timer, T304, CC_T304);
1503 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1504 l3dss1_std_ie_err(pc, ret);
1505 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1509 l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg)
1511 struct sk_buff *skb = arg;
1517 if ((ret = l3dss1_get_cause(pc, skb))) {
1518 if (pc->debug & L3_DEB_WARN)
1519 l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
1525 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
1526 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1527 ret = check_infoelements(pc, skb, ie_DISCONNECT);
1528 if (ERR_IE_COMPREHENSION == ret)
1530 else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
1537 pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
1539 l3dss1_release_req(pc, pr, NULL);
1541 l3dss1_message_cause(pc, MT_RELEASE, cause);
1542 L3AddTimer(&pc->timer, T308, CC_T308_1);
1547 l3dss1_connect(struct l3_process *pc, u_char pr, void *arg)
1549 struct sk_buff *skb = arg;
1552 ret = check_infoelements(pc, skb, ie_CONNECT);
1553 if (ERR_IE_COMPREHENSION == ret) {
1554 l3dss1_std_ie_err(pc, ret);
1557 L3DelTimer(&pc->timer); /* T310 */
1559 pc->para.chargeinfo = 0;
1560 /* here should inserted COLP handling KKe */
1562 l3dss1_std_ie_err(pc, ret);
1563 pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
1567 l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg)
1569 struct sk_buff *skb = arg;
1572 ret = check_infoelements(pc, skb, ie_ALERTING);
1573 if (ERR_IE_COMPREHENSION == ret) {
1574 l3dss1_std_ie_err(pc, ret);
1577 L3DelTimer(&pc->timer); /* T304 */
1580 l3dss1_std_ie_err(pc, ret);
1581 pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
1585 l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
1590 struct sk_buff *skb = arg;
1595 * Bearer Capabilities
1598 /* only the first occurence 'll be detected ! */
1599 if ((p = findie(p, skb->len, 0x04, 0))) {
1600 if ((p[1] < 2) || (p[1] > 11))
1603 pc->para.setup.si2 = 0;
1604 switch (p[2] & 0x7f) {
1605 case 0x00: /* Speech */
1606 case 0x10: /* 3.1 Khz audio */
1607 pc->para.setup.si1 = 1;
1609 case 0x08: /* Unrestricted digital information */
1610 pc->para.setup.si1 = 7;
1611 /* JIM, 05.11.97 I wanna set service indicator 2 */
1612 #ifdef EXT_BEARER_CAPS
1613 pc->para.setup.si2 = DecodeSI2(skb);
1616 case 0x09: /* Restricted digital information */
1617 pc->para.setup.si1 = 2;
1620 /* Unrestr. digital information with
1621 * tones/announcements ( or 7 kHz audio
1623 pc->para.setup.si1 = 3;
1625 case 0x18: /* Video */
1626 pc->para.setup.si1 = 4;
1632 switch (p[3] & 0x7f) {
1633 case 0x40: /* packed mode */
1634 pc->para.setup.si1 = 8;
1636 case 0x10: /* 64 kbit */
1637 case 0x11: /* 2*64 kbit */
1638 case 0x13: /* 384 kbit */
1639 case 0x15: /* 1536 kbit */
1640 case 0x17: /* 1920 kbit */
1641 pc->para.moderate = p[3] & 0x7f;
1648 if (pc->debug & L3_DEB_SI)
1649 l3_debug(pc->st, "SI=%d, AI=%d",
1650 pc->para.setup.si1, pc->para.setup.si2);
1652 if (pc->debug & L3_DEB_WARN)
1653 l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
1655 pc->para.cause = 100;
1656 l3dss1_msg_without_setup(pc, pr, NULL);
1660 if (pc->debug & L3_DEB_WARN)
1661 l3_debug(pc->st, "setup without bearer capabilities");
1662 /* ETS 300-104 1.3.3 */
1663 pc->para.cause = 96;
1664 l3dss1_msg_without_setup(pc, pr, NULL);
1668 * Channel Identification
1670 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1671 if ((pc->para.bchannel = id)) {
1672 if ((3 == id) && (0x10 == pc->para.moderate)) {
1673 if (pc->debug & L3_DEB_WARN)
1674 l3_debug(pc->st, "setup with wrong chid %x",
1676 pc->para.cause = 100;
1677 l3dss1_msg_without_setup(pc, pr, NULL);
1682 { if (pc->debug & L3_DEB_WARN)
1683 l3_debug(pc->st, "setup without bchannel, call waiting");
1687 if (pc->debug & L3_DEB_WARN)
1688 l3_debug(pc->st, "setup with wrong chid ret %d", id);
1690 pc->para.cause = 96;
1692 pc->para.cause = 100;
1693 l3dss1_msg_without_setup(pc, pr, NULL);
1696 /* Now we are on none mandatory IEs */
1697 err = check_infoelements(pc, skb, ie_SETUP);
1698 if (ERR_IE_COMPREHENSION == err) {
1699 pc->para.cause = 96;
1700 l3dss1_msg_without_setup(pc, pr, NULL);
1704 if ((p = findie(p, skb->len, 0x70, 0)))
1705 iecpy(pc->para.setup.eazmsn, p, 1);
1707 pc->para.setup.eazmsn[0] = 0;
1710 if ((p = findie(p, skb->len, 0x71, 0))) {
1711 /* Called party subaddress */
1712 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1714 iecpy(&tmp[1], p, 2);
1715 strcat(pc->para.setup.eazmsn, tmp);
1716 } else if (pc->debug & L3_DEB_WARN)
1717 l3_debug(pc->st, "wrong called subaddress");
1720 if ((p = findie(p, skb->len, 0x6c, 0))) {
1721 pc->para.setup.plan = p[2];
1723 iecpy(pc->para.setup.phone, p, 1);
1724 pc->para.setup.screen = 0;
1726 iecpy(pc->para.setup.phone, p, 2);
1727 pc->para.setup.screen = p[3];
1730 pc->para.setup.phone[0] = 0;
1731 pc->para.setup.plan = 0;
1732 pc->para.setup.screen = 0;
1735 if ((p = findie(p, skb->len, 0x6d, 0))) {
1736 /* Calling party subaddress */
1737 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1739 iecpy(&tmp[1], p, 2);
1740 strcat(pc->para.setup.phone, tmp);
1741 } else if (pc->debug & L3_DEB_WARN)
1742 l3_debug(pc->st, "wrong calling subaddress");
1745 if (err) /* STATUS for none mandatory IE errors after actions are taken */
1746 l3dss1_std_ie_err(pc, err);
1747 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
1751 l3dss1_reset(struct l3_process *pc, u_char pr, void *arg)
1753 dss1_release_l3_process(pc);
1757 l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
1759 struct sk_buff *skb;
1765 if (pc->para.cause != NO_CAUSE)
1766 cause = pc->para.cause;
1770 MsgHead(p, pc->callref, MT_DISCONNECT);
1775 *p++ = cause | 0x80;
1777 if (pc->prot.dss1.uus1_data[0])
1778 { *p++ = IE_USER_USER; /* UUS info element */
1779 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
1780 *p++ = 0x04; /* IA5 chars */
1781 strcpy(p,pc->prot.dss1.uus1_data);
1782 p += strlen(pc->prot.dss1.uus1_data);
1783 pc->prot.dss1.uus1_data[0] = '\0';
1787 if (!(skb = l3_alloc_skb(l)))
1789 memcpy(skb_put(skb, l), tmp, l);
1791 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1792 L3AddTimer(&pc->timer, T305, CC_T305);
1796 l3dss1_setup_rsp(struct l3_process *pc, u_char pr,
1799 if (!pc->para.bchannel)
1800 { if (pc->debug & L3_DEB_WARN)
1801 l3_debug(pc->st, "D-chan connect for waiting call");
1802 l3dss1_disconnect_req(pc, pr, arg);
1806 l3dss1_message(pc, MT_CONNECT);
1807 L3DelTimer(&pc->timer);
1808 L3AddTimer(&pc->timer, T313, CC_T313);
1812 l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
1814 struct sk_buff *skb = arg;
1817 ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
1818 if (ERR_IE_COMPREHENSION == ret) {
1819 l3dss1_std_ie_err(pc, ret);
1823 L3DelTimer(&pc->timer);
1825 l3dss1_std_ie_err(pc, ret);
1826 pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
1830 l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg)
1832 struct sk_buff *skb;
1838 if (pc->para.cause != NO_CAUSE)
1839 cause = pc->para.cause;
1841 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
1846 *p++ = cause | 0x80;
1849 if (!(skb = l3_alloc_skb(l)))
1851 memcpy(skb_put(skb, l), tmp, l);
1852 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1853 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1855 dss1_release_l3_process(pc);
1859 l3dss1_release(struct l3_process *pc, u_char pr, void *arg)
1861 struct sk_buff *skb = arg;
1866 if ((ret = l3dss1_get_cause(pc, skb))>0) {
1867 if (pc->debug & L3_DEB_WARN)
1868 l3_debug(pc->st, "REL get_cause ret(%d)", ret);
1870 pc->para.cause = NO_CAUSE;
1871 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
1872 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1874 if ((ret<0) && (pc->state != 11))
1878 ret = check_infoelements(pc, skb, ie_RELEASE);
1879 if (ERR_IE_COMPREHENSION == ret)
1881 else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
1884 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
1886 l3dss1_message(pc, MT_RELEASE_COMPLETE);
1887 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1889 dss1_release_l3_process(pc);
1893 l3dss1_alert_req(struct l3_process *pc, u_char pr,
1897 if (!pc->prot.dss1.uus1_data[0])
1898 l3dss1_message(pc, MT_ALERTING);
1900 l3dss1_msg_with_uus(pc, MT_ALERTING);
1904 l3dss1_proceed_req(struct l3_process *pc, u_char pr,
1908 l3dss1_message(pc, MT_CALL_PROCEEDING);
1909 pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
1913 l3dss1_setup_ack_req(struct l3_process *pc, u_char pr,
1917 L3DelTimer(&pc->timer);
1918 L3AddTimer(&pc->timer, T302, CC_T302);
1919 l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
1922 /********************************************/
1923 /* deliver a incoming display message to HL */
1924 /********************************************/
1926 l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
1929 struct IsdnCardState *cs;
1932 if (*infp++ != IE_DISPLAY) return;
1933 if ((len = *infp++) > 80) return; /* total length <= 82 */
1934 if (!pc->chan) return;
1936 p = ic.parm.display;
1940 ic.command = ISDN_STAT_DISPLAY;
1941 cs = pc->st->l1.hardware;
1942 ic.driver = cs->myid;
1943 ic.arg = pc->chan->chan;
1944 cs->iif.statcallb(&ic);
1945 } /* l3dss1_deliver_display */
1949 l3dss1_progress(struct l3_process *pc, u_char pr, void *arg)
1951 struct sk_buff *skb = arg;
1955 if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
1958 pc->para.cause = 100;
1959 } else if (!(p[2] & 0x70)) {
1977 pc->para.cause = 100;
1983 pc->para.cause = 100;
1988 pc->para.cause = 96;
1992 if (pc->debug & L3_DEB_WARN)
1993 l3_debug(pc->st, "progress error %d", err);
1994 l3dss1_status_send(pc, pr, NULL);
1997 /* Now we are on none mandatory IEs */
1998 err = check_infoelements(pc, skb, ie_PROGRESS);
2000 l3dss1_std_ie_err(pc, err);
2001 if (ERR_IE_COMPREHENSION != err)
2002 pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
2006 l3dss1_notify(struct l3_process *pc, u_char pr, void *arg)
2008 struct sk_buff *skb = arg;
2012 if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
2015 pc->para.cause = 100;
2023 pc->para.cause = 100;
2029 pc->para.cause = 96;
2033 if (pc->debug & L3_DEB_WARN)
2034 l3_debug(pc->st, "notify error %d", err);
2035 l3dss1_status_send(pc, pr, NULL);
2038 /* Now we are on none mandatory IEs */
2039 err = check_infoelements(pc, skb, ie_NOTIFY);
2041 l3dss1_std_ie_err(pc, err);
2042 if (ERR_IE_COMPREHENSION != err)
2043 pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
2047 l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg)
2050 struct sk_buff *skb = arg;
2052 ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
2053 l3dss1_std_ie_err(pc, ret);
2054 pc->para.cause = 30; /* response to STATUS_ENQUIRY */
2055 l3dss1_status_send(pc, pr, NULL);
2059 l3dss1_information(struct l3_process *pc, u_char pr, void *arg)
2062 struct sk_buff *skb = arg;
2066 ret = check_infoelements(pc, skb, ie_INFORMATION);
2068 l3dss1_std_ie_err(pc, ret);
2069 if (pc->state == 25) { /* overlap receiving */
2070 L3DelTimer(&pc->timer);
2072 if ((p = findie(p, skb->len, 0x70, 0))) {
2074 strcat(pc->para.setup.eazmsn, tmp);
2075 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
2077 L3AddTimer(&pc->timer, T302, CC_T302);
2081 /******************************/
2082 /* handle deflection requests */
2083 /******************************/
2084 static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg)
2086 struct sk_buff *skb;
2090 u_char len_phone = 0;
2095 strcpy(pc->prot.dss1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
2096 if (!pc->chan->setup.phone[0])
2097 { pc->para.cause = -1;
2098 l3dss1_disconnect_req(pc,pr,arg); /* disconnect immediately */
2102 if (pc->prot.dss1.invoke_id)
2103 free_invoke_id(pc->st,pc->prot.dss1.invoke_id);
2105 if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
2108 MsgHead(p, pc->callref, MT_FACILITY);
2110 for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
2111 if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
2113 *p++ = 0x1c; /* Facility info element */
2114 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
2115 *p++ = 0x91; /* remote operations protocol */
2116 *p++ = 0xa1; /* invoke component */
2118 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
2119 *p++ = 0x02; /* invoke id tag, integer */
2120 *p++ = 0x01; /* length */
2121 *p++ = pc->prot.dss1.invoke_id; /* invoke id */
2122 *p++ = 0x02; /* operation value tag, integer */
2123 *p++ = 0x01; /* length */
2124 *p++ = 0x0D; /* Call Deflect */
2126 *p++ = 0x30; /* sequence phone number */
2127 *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
2129 *p++ = 0x30; /* Deflected to UserNumber */
2130 *p++ = len_phone+2+len_sub; /* length */
2131 *p++ = 0x80; /* NumberDigits */
2132 *p++ = len_phone; /* length */
2133 for (l = 0; l < len_phone; l++)
2134 *p++ = pc->chan->setup.phone[l];
2137 { *p++ = 0x04; /* called party subaddress */
2139 while (*subp) *p++ = *subp++;
2142 *p++ = 0x01; /* screening identifier */
2144 *p++ = pc->chan->setup.screen;
2147 if (!(skb = l3_alloc_skb(l))) return;
2148 memcpy(skb_put(skb, l), tmp, l);
2150 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2151 } /* l3dss1_redir_req */
2153 /********************************************/
2154 /* handle deflection request in early state */
2155 /********************************************/
2156 static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
2158 l3dss1_proceed_req(pc,pr,arg);
2159 l3dss1_redir_req(pc,pr,arg);
2160 } /* l3dss1_redir_req_early */
2162 /***********************************************/
2163 /* handle special commands for this protocol. */
2164 /* Examples are call independant services like */
2165 /* remote operations with dummy callref. */
2166 /***********************************************/
2167 static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
2172 struct sk_buff *skb;
2173 struct l3_process *pc = NULL;
2176 { case DSS1_CMD_INVOKE:
2177 if (ic->parm.dss1_io.datalen < 0) return(-2); /* invalid parameter */
2179 for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
2180 i = i >> 8; /* add one byte */
2181 l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
2183 return(-2); /* too long */
2185 if (!(id = new_invoke_id(st)))
2186 return(0); /* first get a invoke id -> return if no available */
2189 MsgHead(p, i, MT_FACILITY); /* build message head */
2190 *p++ = 0x1C; /* Facility IE */
2191 *p++ = l; /* length of ie */
2192 *p++ = 0x91; /* remote operations */
2193 *p++ = 0xA1; /* invoke */
2194 *p++ = l - 3; /* length of invoke */
2195 *p++ = 0x02; /* invoke id tag */
2196 *p++ = 0x01; /* length is 1 */
2197 *p++ = id; /* invoke id */
2198 *p++ = 0x02; /* operation */
2199 *p++ = proc_len; /* length of operation */
2201 for (i = proc_len; i; i--)
2202 *p++ = (ic->parm.dss1_io.proc >> (i-1)) & 0xFF;
2203 memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
2204 l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
2206 if (ic->parm.dss1_io.timeout > 0)
2207 if (!(pc = dss1_new_l3_process(st, -1)))
2208 { free_invoke_id(st, id);
2211 pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
2212 pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
2214 if (!(skb = l3_alloc_skb(l)))
2215 { free_invoke_id(st, id);
2216 if (pc) dss1_release_l3_process(pc);
2219 memcpy(skb_put(skb, l), temp, l);
2222 { pc->prot.dss1.invoke_id = id; /* remember id */
2223 L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
2226 l3_msg(st, DL_DATA | REQUEST, skb);
2227 ic->parm.dss1_io.hl_id = id; /* return id */
2230 case DSS1_CMD_INVOKE_ABORT:
2231 if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
2232 { L3DelTimer(&pc->timer); /* remove timer */
2233 dss1_release_l3_process(pc);
2237 { l3_debug(st, "l3dss1_cmd_global abort unknown id");
2243 l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
2245 } /* switch ic-> arg */
2247 } /* l3dss1_cmd_global */
2250 l3dss1_io_timer(struct l3_process *pc)
2252 struct IsdnCardState *cs = pc->st->l1.hardware;
2254 L3DelTimer(&pc->timer); /* remove timer */
2256 ic.driver = cs->myid;
2257 ic.command = ISDN_STAT_PROT;
2258 ic.arg = DSS1_STAT_INVOKE_ERR;
2259 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
2260 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
2261 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
2262 ic.parm.dss1_io.timeout= -1;
2263 ic.parm.dss1_io.datalen = 0;
2264 ic.parm.dss1_io.data = NULL;
2265 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
2266 pc->prot.dss1.invoke_id = 0; /* reset id */
2268 cs->iif.statcallb(&ic);
2270 dss1_release_l3_process(pc);
2271 } /* l3dss1_io_timer */
2274 l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg)
2277 struct sk_buff *skb = arg;
2281 if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
2286 if (callState == 0) {
2287 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
2288 * set down layer 3 without sending any message
2290 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2292 dss1_release_l3_process(pc);
2294 pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
2299 l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg)
2304 l3dss1_t302(struct l3_process *pc, u_char pr, void *arg)
2306 L3DelTimer(&pc->timer);
2308 pc->para.cause = 28; /* invalid number */
2309 l3dss1_disconnect_req(pc, pr, NULL);
2310 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2314 l3dss1_t303(struct l3_process *pc, u_char pr, void *arg)
2318 L3DelTimer(&pc->timer);
2319 l3dss1_setup_req(pc, pr, arg);
2321 L3DelTimer(&pc->timer);
2322 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
2323 pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
2324 dss1_release_l3_process(pc);
2329 l3dss1_t304(struct l3_process *pc, u_char pr, void *arg)
2331 L3DelTimer(&pc->timer);
2333 pc->para.cause = 102;
2334 l3dss1_disconnect_req(pc, pr, NULL);
2335 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2340 l3dss1_t305(struct l3_process *pc, u_char pr, void *arg)
2345 struct sk_buff *skb;
2348 L3DelTimer(&pc->timer);
2349 if (pc->para.cause != NO_CAUSE)
2350 cause = pc->para.cause;
2352 MsgHead(p, pc->callref, MT_RELEASE);
2357 *p++ = cause | 0x80;
2360 if (!(skb = l3_alloc_skb(l)))
2362 memcpy(skb_put(skb, l), tmp, l);
2364 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2365 L3AddTimer(&pc->timer, T308, CC_T308_1);
2369 l3dss1_t310(struct l3_process *pc, u_char pr, void *arg)
2371 L3DelTimer(&pc->timer);
2373 pc->para.cause = 102;
2374 l3dss1_disconnect_req(pc, pr, NULL);
2375 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2379 l3dss1_t313(struct l3_process *pc, u_char pr, void *arg)
2381 L3DelTimer(&pc->timer);
2383 pc->para.cause = 102;
2384 l3dss1_disconnect_req(pc, pr, NULL);
2385 pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
2389 l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg)
2392 L3DelTimer(&pc->timer);
2393 l3dss1_message(pc, MT_RELEASE);
2394 L3AddTimer(&pc->timer, T308, CC_T308_2);
2398 l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg)
2400 L3DelTimer(&pc->timer);
2401 pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
2402 dss1_release_l3_process(pc);
2406 l3dss1_t318(struct l3_process *pc, u_char pr, void *arg)
2408 L3DelTimer(&pc->timer);
2409 pc->para.cause = 102; /* Timer expiry */
2410 pc->para.loc = 0; /* local */
2411 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2413 l3dss1_message(pc, MT_RELEASE);
2414 L3AddTimer(&pc->timer, T308, CC_T308_1);
2418 l3dss1_t319(struct l3_process *pc, u_char pr, void *arg)
2420 L3DelTimer(&pc->timer);
2421 pc->para.cause = 102; /* Timer expiry */
2422 pc->para.loc = 0; /* local */
2423 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2428 l3dss1_restart(struct l3_process *pc, u_char pr, void *arg)
2430 L3DelTimer(&pc->timer);
2431 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2432 dss1_release_l3_process(pc);
2436 l3dss1_status(struct l3_process *pc, u_char pr, void *arg)
2439 struct sk_buff *skb = arg;
2441 u_char cause = 0, callState = 0;
2443 if ((ret = l3dss1_get_cause(pc, skb))) {
2444 if (pc->debug & L3_DEB_WARN)
2445 l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
2451 if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
2455 if (!ie_in_set(pc, *p, l3_valid_states))
2461 if (!cause) { /* no error before */
2462 ret = check_infoelements(pc, skb, ie_STATUS);
2463 if (ERR_IE_COMPREHENSION == ret)
2465 else if (ERR_IE_UNRECOGNIZED == ret)
2471 if (pc->debug & L3_DEB_WARN)
2472 l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
2473 tmp = pc->para.cause;
2474 pc->para.cause = cause;
2475 l3dss1_status_send(pc, 0, NULL);
2477 pc->para.cause = tmp;
2481 cause = pc->para.cause;
2482 if (((cause & 0x7f) == 111) && (callState == 0)) {
2483 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
2484 * if received MT_STATUS with cause == 111 and call
2485 * state == 0, then we must set down layer 3
2487 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2489 dss1_release_l3_process(pc);
2494 l3dss1_facility(struct l3_process *pc, u_char pr, void *arg)
2496 struct sk_buff *skb = arg;
2499 ret = check_infoelements(pc, skb, ie_FACILITY);
2500 l3dss1_std_ie_err(pc, ret);
2503 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
2504 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
2509 l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
2511 struct sk_buff *skb;
2515 u_char *msg = pc->chan->setup.phone;
2517 MsgHead(p, pc->callref, MT_SUSPEND);
2519 if (l && (l <= 10)) { /* Max length 10 octets */
2522 for (i = 0; i < l; i++)
2525 l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
2529 if (!(skb = l3_alloc_skb(l)))
2531 memcpy(skb_put(skb, l), tmp, l);
2532 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2534 L3AddTimer(&pc->timer, T319, CC_T319);
2538 l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
2540 struct sk_buff *skb = arg;
2543 L3DelTimer(&pc->timer);
2545 pc->para.cause = NO_CAUSE;
2546 pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
2547 /* We don't handle suspend_ack for IE errors now */
2548 if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
2549 if (pc->debug & L3_DEB_WARN)
2550 l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
2551 dss1_release_l3_process(pc);
2555 l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
2557 struct sk_buff *skb = arg;
2560 if ((ret = l3dss1_get_cause(pc, skb))) {
2561 if (pc->debug & L3_DEB_WARN)
2562 l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
2564 pc->para.cause = 96;
2566 pc->para.cause = 100;
2567 l3dss1_status_send(pc, pr, NULL);
2570 ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
2571 if (ERR_IE_COMPREHENSION == ret) {
2572 l3dss1_std_ie_err(pc, ret);
2575 L3DelTimer(&pc->timer);
2576 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2578 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2579 l3dss1_std_ie_err(pc, ret);
2583 l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg)
2585 struct sk_buff *skb;
2589 u_char *msg = pc->para.setup.phone;
2591 MsgHead(p, pc->callref, MT_RESUME);
2594 if (l && (l <= 10)) { /* Max length 10 octets */
2597 for (i = 0; i < l; i++)
2600 l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
2604 if (!(skb = l3_alloc_skb(l)))
2606 memcpy(skb_put(skb, l), tmp, l);
2607 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2609 L3AddTimer(&pc->timer, T318, CC_T318);
2613 l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
2615 struct sk_buff *skb = arg;
2618 if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
2619 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
2620 if (pc->debug & L3_DEB_WARN)
2621 l3_debug(pc->st, "resume ack with wrong chid %x", id);
2622 pc->para.cause = 100;
2623 l3dss1_status_send(pc, pr, NULL);
2626 pc->para.bchannel = id;
2627 } else if (1 == pc->state) {
2628 if (pc->debug & L3_DEB_WARN)
2629 l3_debug(pc->st, "resume ack without chid (ret %d)", id);
2630 pc->para.cause = 96;
2631 l3dss1_status_send(pc, pr, NULL);
2634 ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
2635 if (ERR_IE_COMPREHENSION == ret) {
2636 l3dss1_std_ie_err(pc, ret);
2639 L3DelTimer(&pc->timer);
2640 pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
2642 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2643 l3dss1_std_ie_err(pc, ret);
2647 l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
2649 struct sk_buff *skb = arg;
2652 if ((ret = l3dss1_get_cause(pc, skb))) {
2653 if (pc->debug & L3_DEB_WARN)
2654 l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
2656 pc->para.cause = 96;
2658 pc->para.cause = 100;
2659 l3dss1_status_send(pc, pr, NULL);
2662 ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
2663 if (ERR_IE_COMPREHENSION == ret) {
2664 l3dss1_std_ie_err(pc, ret);
2667 L3DelTimer(&pc->timer);
2668 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2670 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2671 l3dss1_std_ie_err(pc, ret);
2672 dss1_release_l3_process(pc);
2676 l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg)
2680 u_char ri, ch = 0, chan = 0;
2682 struct sk_buff *skb = arg;
2683 struct l3_process *up;
2686 L3DelTimer(&pc->timer);
2688 if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
2690 l3_debug(pc->st, "Restart %x", ri);
2692 l3_debug(pc->st, "Restart without restart IE");
2696 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
2699 if (pc->st->l3.debug)
2700 l3_debug(pc->st, "Restart for channel %d", chan);
2703 up = pc->st->l3.proc;
2706 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2707 else if (up->para.bchannel == chan)
2708 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2712 MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
2714 *p++ = IE_CHANNEL_ID;
2718 *p++ = 0x79; /* RESTART Ind */
2722 if (!(skb = l3_alloc_skb(l)))
2724 memcpy(skb_put(skb, l), tmp, l);
2726 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2730 l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
2732 pc->para.cause = 0x29; /* Temporary failure */
2734 l3dss1_disconnect_req(pc, pr, NULL);
2735 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2739 l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg)
2742 pc->para.cause = 0x1b; /* Destination out of order */
2744 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2745 release_l3_process(pc);
2749 l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
2751 L3DelTimer(&pc->timer);
2752 L3AddTimer(&pc->timer, T309, CC_T309);
2753 l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
2757 l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
2759 L3DelTimer(&pc->timer);
2761 pc->para.cause = 0x1F; /* normal, unspecified */
2762 l3dss1_status_send(pc, 0, NULL);
2766 static struct stateentry downstatelist[] =
2769 CC_SETUP | REQUEST, l3dss1_setup_req},
2771 CC_RESUME | REQUEST, l3dss1_resume_req},
2772 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
2773 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2775 CC_RELEASE | REQUEST, l3dss1_release_req},
2777 CC_RESTART | REQUEST, l3dss1_restart},
2778 {SBIT(6) | SBIT(25),
2779 CC_IGNORE | REQUEST, l3dss1_reset},
2780 {SBIT(6) | SBIT(25),
2781 CC_REJECT | REQUEST, l3dss1_reject_req},
2782 {SBIT(6) | SBIT(25),
2783 CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
2785 CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
2787 CC_MORE_INFO | REQUEST, l3dss1_dummy},
2788 {SBIT(6) | SBIT(9) | SBIT(25),
2789 CC_ALERTING | REQUEST, l3dss1_alert_req},
2790 {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
2791 CC_SETUP | RESPONSE, l3dss1_setup_rsp},
2793 CC_SUSPEND | REQUEST, l3dss1_suspend_req},
2794 {SBIT(7) | SBIT(9) | SBIT(25),
2795 CC_REDIR | REQUEST, l3dss1_redir_req},
2797 CC_REDIR | REQUEST, l3dss1_redir_req_early},
2798 {SBIT(9) | SBIT(25),
2799 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2801 CC_T302, l3dss1_t302},
2803 CC_T303, l3dss1_t303},
2805 CC_T304, l3dss1_t304},
2807 CC_T310, l3dss1_t310},
2809 CC_T313, l3dss1_t313},
2811 CC_T305, l3dss1_t305},
2813 CC_T319, l3dss1_t319},
2815 CC_T318, l3dss1_t318},
2817 CC_T308_1, l3dss1_t308_1},
2819 CC_T308_2, l3dss1_t308_2},
2821 CC_T309, l3dss1_dl_release},
2825 (sizeof(downstatelist) / sizeof(struct stateentry))
2827 static struct stateentry datastatelist[] =
2830 MT_STATUS_ENQUIRY, l3dss1_status_enq},
2832 MT_FACILITY, l3dss1_facility},
2834 MT_STATUS, l3dss1_release_ind},
2836 MT_STATUS, l3dss1_status},
2838 MT_SETUP, l3dss1_setup},
2839 {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
2840 SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2841 MT_SETUP, l3dss1_dummy},
2843 MT_CALL_PROCEEDING, l3dss1_call_proc},
2845 MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
2847 MT_ALERTING, l3dss1_alerting},
2849 MT_PROGRESS, l3dss1_progress},
2850 {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
2851 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2852 MT_INFORMATION, l3dss1_information},
2853 {SBIT(10) | SBIT(11) | SBIT(15),
2854 MT_NOTIFY, l3dss1_notify},
2855 {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
2856 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2857 MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
2858 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(25),
2859 MT_RELEASE, l3dss1_release},
2860 {SBIT(19), MT_RELEASE, l3dss1_release_ind},
2861 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
2862 MT_DISCONNECT, l3dss1_disconnect},
2864 MT_DISCONNECT, l3dss1_dummy},
2865 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
2866 MT_CONNECT, l3dss1_connect},
2868 MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
2870 MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
2872 MT_SUSPEND_REJECT, l3dss1_suspend_rej},
2874 MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
2876 MT_RESUME_REJECT, l3dss1_resume_rej},
2880 (sizeof(datastatelist) / sizeof(struct stateentry))
2882 static struct stateentry globalmes_list[] =
2885 MT_STATUS, l3dss1_status},
2887 MT_RESTART, l3dss1_global_restart},
2889 MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
2892 #define GLOBALM_LEN \
2893 (sizeof(globalmes_list) / sizeof(struct stateentry))
2895 static struct stateentry manstatelist[] =
2898 DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
2900 DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
2902 DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
2904 DL_RELEASE | INDICATION, l3dss1_dl_release},
2908 (sizeof(manstatelist) / sizeof(struct stateentry))
2913 global_handler(struct PStack *st, int mt, struct sk_buff *skb)
2919 struct l3_process *proc = st->l3.global;
2921 proc->callref = skb->data[2]; /* cr flag */
2922 for (i = 0; i < GLOBALM_LEN; i++)
2923 if ((mt == globalmes_list[i].primitive) &&
2924 ((1 << proc->state) & globalmes_list[i].state))
2926 if (i == GLOBALM_LEN) {
2927 if (st->l3.debug & L3_DEB_STATE) {
2928 l3_debug(st, "dss1 global state %d mt %x unhandled",
2931 MsgHead(p, proc->callref, MT_STATUS);
2935 *p++ = 81 |0x80; /* invalid cr */
2936 *p++ = 0x14; /* CallState */
2938 *p++ = proc->state & 0x3f;
2940 if (!(skb = l3_alloc_skb(l)))
2942 memcpy(skb_put(skb, l), tmp, l);
2943 l3_msg(proc->st, DL_DATA | REQUEST, skb);
2945 if (st->l3.debug & L3_DEB_STATE) {
2946 l3_debug(st, "dss1 global %d mt %x",
2949 globalmes_list[i].rout(proc, mt, skb);
2954 dss1up(struct PStack *st, int pr, void *arg)
2956 int i, mt, cr, cause, callState;
2959 struct sk_buff *skb = arg;
2960 struct l3_process *proc;
2963 case (DL_DATA | INDICATION):
2964 case (DL_UNIT_DATA | INDICATION):
2966 case (DL_ESTABLISH | CONFIRM):
2967 case (DL_ESTABLISH | INDICATION):
2968 case (DL_RELEASE | INDICATION):
2969 case (DL_RELEASE | CONFIRM):
2970 l3_msg(st, pr, arg);
2974 printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
2978 l3_debug(st, "dss1up frame too short(%d)", skb->len);
2983 if (skb->data[0] != PROTO_DIS_EURO) {
2984 if (st->l3.debug & L3_DEB_PROTERR) {
2985 l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
2986 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
2987 skb->data[0], skb->len);
2992 cr = getcallref(skb->data);
2993 if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
2994 l3_debug(st, "dss1up frame too short(%d)", skb->len);
2998 mt = skb->data[skb->data[1] + 2];
2999 if (st->l3.debug & L3_DEB_STATE)
3000 l3_debug(st, "dss1up cr %d", cr);
3001 if (cr == -2) { /* wrong Callref */
3002 if (st->l3.debug & L3_DEB_WARN)
3003 l3_debug(st, "dss1up wrong Callref");
3006 } else if (cr == -1) { /* Dummy Callref */
3007 if (mt == MT_FACILITY)
3008 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
3009 l3dss1_parse_facility(st, NULL,
3010 (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
3014 if (st->l3.debug & L3_DEB_WARN)
3015 l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
3018 } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
3019 (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
3020 if (st->l3.debug & L3_DEB_STATE)
3021 l3_debug(st, "dss1up Global CallRef");
3022 global_handler(st, mt, skb);
3025 } else if (!(proc = getl3proc(st, cr))) {
3026 /* No transaction process exist, that means no call with
3027 * this callreference is active
3029 if (mt == MT_SETUP) {
3030 /* Setup creates a new transaction process */
3031 if (skb->data[2] & 0x80) {
3032 /* Setup with wrong CREF flag */
3033 if (st->l3.debug & L3_DEB_STATE)
3034 l3_debug(st, "dss1up wrong CRef flag");
3038 if (!(proc = dss1_new_l3_process(st, cr))) {
3039 /* May be to answer with RELEASE_COMPLETE and
3040 * CAUSE 0x2f "Resource unavailable", but this
3041 * need a new_l3_process too ... arghh
3046 } else if (mt == MT_STATUS) {
3048 if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
3052 cause = *ptr & 0x7f;
3055 if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
3061 /* ETS 300-104 part 2.4.1
3062 * if setup has not been made and a message type
3063 * MT_STATUS is received with call state == 0,
3064 * we must send nothing
3066 if (callState != 0) {
3067 /* ETS 300-104 part 2.4.2
3068 * if setup has not been made and a message type
3069 * MT_STATUS is received with call state != 0,
3070 * we must send MT_RELEASE_COMPLETE cause 101
3072 if ((proc = dss1_new_l3_process(st, cr))) {
3073 proc->para.cause = 101;
3074 l3dss1_msg_without_setup(proc, 0, NULL);
3079 } else if (mt == MT_RELEASE_COMPLETE) {
3083 /* ETS 300-104 part 2
3084 * if setup has not been made and a message type
3085 * (except MT_SETUP and RELEASE_COMPLETE) is received,
3086 * we must send MT_RELEASE_COMPLETE cause 81 */
3088 if ((proc = dss1_new_l3_process(st, cr))) {
3089 proc->para.cause = 81;
3090 l3dss1_msg_without_setup(proc, 0, NULL);
3095 if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
3099 if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
3100 l3dss1_deliver_display(proc, pr, p); /* Display IE included */
3101 for (i = 0; i < DATASLLEN; i++)
3102 if ((mt == datastatelist[i].primitive) &&
3103 ((1 << proc->state) & datastatelist[i].state))
3105 if (i == DATASLLEN) {
3106 if (st->l3.debug & L3_DEB_STATE) {
3107 l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
3108 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3111 if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
3112 proc->para.cause = 101;
3113 l3dss1_status_send(proc, pr, skb);
3116 if (st->l3.debug & L3_DEB_STATE) {
3117 l3_debug(st, "dss1up%sstate %d mt %x",
3118 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3121 datastatelist[i].rout(proc, pr, skb);
3128 dss1down(struct PStack *st, int pr, void *arg)
3131 struct l3_process *proc;
3132 struct Channel *chan;
3134 if ((DL_ESTABLISH | REQUEST) == pr) {
3135 l3_msg(st, pr, NULL);
3137 } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
3141 if ((proc = dss1_new_l3_process(st, cr))) {
3144 memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
3151 printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
3155 if ( pr == (CC_TDSS1_IO | REQUEST)) {
3156 l3dss1_io_timer(proc); /* timer expires */
3160 for (i = 0; i < DOWNSLLEN; i++)
3161 if ((pr == downstatelist[i].primitive) &&
3162 ((1 << proc->state) & downstatelist[i].state))
3164 if (i == DOWNSLLEN) {
3165 if (st->l3.debug & L3_DEB_STATE) {
3166 l3_debug(st, "dss1down state %d prim %#x unhandled",
3170 if (st->l3.debug & L3_DEB_STATE) {
3171 l3_debug(st, "dss1down state %d prim %#x",
3174 downstatelist[i].rout(proc, pr, arg);
3179 dss1man(struct PStack *st, int pr, void *arg)
3182 struct l3_process *proc = arg;
3185 printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
3188 for (i = 0; i < MANSLLEN; i++)
3189 if ((pr == manstatelist[i].primitive) &&
3190 ((1 << proc->state) & manstatelist[i].state))
3192 if (i == MANSLLEN) {
3193 if (st->l3.debug & L3_DEB_STATE) {
3194 l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
3195 proc->callref & 0x7f, proc->state, pr);
3198 if (st->l3.debug & L3_DEB_STATE) {
3199 l3_debug(st, "cr %d dss1man state %d prim %#x",
3200 proc->callref & 0x7f, proc->state, pr);
3202 manstatelist[i].rout(proc, pr, arg);
3207 setstack_dss1(struct PStack *st)
3212 st->lli.l4l3 = dss1down;
3213 st->lli.l4l3_proto = l3dss1_cmd_global;
3214 st->l2.l2l3 = dss1up;
3215 st->l3.l3ml3 = dss1man;
3217 st->prot.dss1.last_invoke_id = 0;
3218 st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
3221 st->prot.dss1.invoke_used[i++] = 0;
3223 if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
3224 printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
3226 st->l3.global->state = 0;
3227 st->l3.global->callref = 0;
3228 st->l3.global->next = NULL;
3229 st->l3.global->debug = L3_DEB_WARN;
3230 st->l3.global->st = st;
3231 st->l3.global->N303 = 1;
3232 st->l3.global->prot.dss1.invoke_id = 0;
3234 L3InitTimer(st->l3.global, &st->l3.global->timer);
3236 strcpy(tmp, dss1_revision);
3237 printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));