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>
27 extern char *HiSax_getrev(const char *revision);
28 static const char *dss1_revision = "$Revision: 2.32.2.3 $";
30 #define EXT_BEARER_CAPS 1
32 #define MsgHead(ptr, cref, mty) \
43 /**********************************************/
44 /* get a new invoke id for remote operations. */
45 /* Only a return value != 0 is valid */
46 /**********************************************/
47 static unsigned char new_invoke_id(struct PStack *p)
52 i = 32; /* maximum search depth */
54 retval = p->prot.dss1.last_invoke_id + 1; /* try new id */
55 while ((i) && (p->prot.dss1.invoke_used[retval >> 3] == 0xFF)) {
56 p->prot.dss1.last_invoke_id = (retval & 0xF8) + 8;
60 while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7)))
64 p->prot.dss1.last_invoke_id = retval;
65 p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7));
69 /*************************/
70 /* free a used invoke id */
71 /*************************/
72 static void free_invoke_id(struct PStack *p, unsigned char id)
75 if (!id) return; /* 0 = invalid value */
77 p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7));
78 } /* free_invoke_id */
81 /**********************************************************/
82 /* create a new l3 process and fill in dss1 specific data */
83 /**********************************************************/
84 static struct l3_process
85 *dss1_new_l3_process(struct PStack *st, int cr)
86 { struct l3_process *proc;
88 if (!(proc = new_l3_process(st, cr)))
91 proc->prot.dss1.invoke_id = 0;
92 proc->prot.dss1.remote_operation = 0;
93 proc->prot.dss1.uus1_data[0] = '\0';
96 } /* dss1_new_l3_process */
98 /************************************************/
99 /* free a l3 process and all dss1 specific data */
100 /************************************************/
102 dss1_release_l3_process(struct l3_process *p)
104 free_invoke_id(p->st,p->prot.dss1.invoke_id);
105 release_l3_process(p);
106 } /* dss1_release_l3_process */
108 /********************************************************/
109 /* search a process with invoke id id and dummy callref */
110 /********************************************************/
111 static struct l3_process *
112 l3dss1_search_dummy_proc(struct PStack *st, int id)
113 { struct l3_process *pc = st->l3.proc; /* start of processes */
115 if (!id) return(NULL);
118 { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id))
123 } /* l3dss1_search_dummy_proc */
125 /*******************************************************************/
126 /* called when a facility message with a dummy callref is received */
127 /* and a return result is delivered. id specifies the invoke id. */
128 /*******************************************************************/
130 l3dss1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
132 struct IsdnCardState *cs;
133 struct l3_process *pc = NULL;
135 if ((pc = l3dss1_search_dummy_proc(st, id)))
136 { L3DelTimer(&pc->timer); /* remove timer */
138 cs = pc->st->l1.hardware;
139 ic.driver = cs->myid;
140 ic.command = ISDN_STAT_PROT;
141 ic.arg = DSS1_STAT_INVOKE_RES;
142 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
143 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
144 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
145 ic.parm.dss1_io.timeout= 0;
146 ic.parm.dss1_io.datalen = nlen;
147 ic.parm.dss1_io.data = p;
148 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
149 pc->prot.dss1.invoke_id = 0; /* reset id */
151 cs->iif.statcallb(&ic);
152 dss1_release_l3_process(pc);
155 l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
156 } /* l3dss1_dummy_return_result */
158 /*******************************************************************/
159 /* called when a facility message with a dummy callref is received */
160 /* and a return error is delivered. id specifies the invoke id. */
161 /*******************************************************************/
163 l3dss1_dummy_error_return(struct PStack *st, int id, ulong error)
165 struct IsdnCardState *cs;
166 struct l3_process *pc = NULL;
168 if ((pc = l3dss1_search_dummy_proc(st, id)))
169 { L3DelTimer(&pc->timer); /* remove timer */
171 cs = pc->st->l1.hardware;
172 ic.driver = cs->myid;
173 ic.command = ISDN_STAT_PROT;
174 ic.arg = DSS1_STAT_INVOKE_ERR;
175 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
176 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
177 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
178 ic.parm.dss1_io.timeout= error;
179 ic.parm.dss1_io.datalen = 0;
180 ic.parm.dss1_io.data = NULL;
181 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
182 pc->prot.dss1.invoke_id = 0; /* reset id */
184 cs->iif.statcallb(&ic);
185 dss1_release_l3_process(pc);
188 l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
189 } /* l3dss1_error_return */
191 /*******************************************************************/
192 /* called when a facility message with a dummy callref is received */
193 /* and a invoke is delivered. id specifies the invoke id. */
194 /*******************************************************************/
196 l3dss1_dummy_invoke(struct PStack *st, int cr, int id,
197 int ident, u_char *p, u_char nlen)
199 struct IsdnCardState *cs;
201 l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
202 (cr == -1) ? "local" : "broadcast",id,ident,nlen);
203 if (cr >= -1) return; /* ignore local data */
205 cs = st->l1.hardware;
206 ic.driver = cs->myid;
207 ic.command = ISDN_STAT_PROT;
208 ic.arg = DSS1_STAT_INVOKE_BRD;
209 ic.parm.dss1_io.hl_id = id;
210 ic.parm.dss1_io.ll_id = 0;
211 ic.parm.dss1_io.proc = ident;
212 ic.parm.dss1_io.timeout= 0;
213 ic.parm.dss1_io.datalen = nlen;
214 ic.parm.dss1_io.data = p;
216 cs->iif.statcallb(&ic);
217 } /* l3dss1_dummy_invoke */
220 l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
224 unsigned char nlen = 0, ilen, cp_tag;
229 st = pc->st; /* valid Stack */
231 if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
236 l3_debug(st, "qd_len == 0");
239 if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
240 l3_debug(st, "supplementary service != 0x11");
243 while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
248 l3_debug(st, "qd_len < 2");
253 if ((*p & 0xE0) != 0xA0) { /* class and form */
254 l3_debug(st, "class and form != 0xA0");
258 cp_tag = *p & 0x1F; /* remember tag value */
263 { l3_debug(st, "qd_len < 1");
267 { /* length format indefinite or limited */
268 nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
269 if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
271 { l3_debug(st, "length format error or not implemented");
275 { nlen = *p++; /* complete length */
279 { qd_len -= 2; /* trailing null bytes */
280 if ((*(p+qd_len)) || (*(p+qd_len+1)))
281 { l3_debug(st,"length format indefinite error");
292 { l3_debug(st, "qd_len < nlen");
298 { l3_debug(st, "nlen < 2");
302 { /* invoke identifier tag */
303 l3_debug(st, "invoke identifier tag !=0x02");
309 { /* length format */
310 l3_debug(st, "invoke id length format 2");
315 if (ilen > nlen || ilen == 0)
316 { l3_debug(st, "ilen > nlen || ilen == 0");
322 { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
326 switch (cp_tag) { /* component tag */
329 l3_debug(st, "nlen < 2 22");
332 if (*p != 0x02) { /* operation value */
333 l3_debug(st, "operation value !=0x02");
340 if (ilen > nlen || ilen == 0) {
341 l3_debug(st, "ilen > nlen || ilen == 0 22");
347 ident = (ident << 8) | (*p++ & 0xFF);
352 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
358 #define FOO1(s,a,b) \
361 if(nlen < ilen+2) { \
362 l3_debug(st, "FOO1 nlen < ilen+2"); \
366 if((*p & 0xFF) == (a)) { \
376 case 0x22: /* during */
377 FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( {
379 nlen = (nlen)?nlen:0; /* Make gcc happy */
381 ident = (ident << 8) | *p++;
384 if (ident > pc->para.chargeinfo) {
385 pc->para.chargeinfo = ident;
386 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
388 if (st->l3.debug & L3_DEB_CHARGE) {
390 l3_debug(st, "charging info during %d", pc->para.chargeinfo);
393 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
399 case 0x24: /* final */
400 FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( {
402 nlen = (nlen)?nlen:0; /* Make gcc happy */
404 ident = (ident << 8) | *p++;
407 if (ident > pc->para.chargeinfo) {
408 pc->para.chargeinfo = ident;
409 st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
411 if (st->l3.debug & L3_DEB_CHARGE) {
412 l3_debug(st, "charging info final %d", pc->para.chargeinfo);
418 l3_debug(st, "invoke break invalid ident %02x",ident);
424 #else /* not HISAX_DE_AOC */
425 l3_debug(st, "invoke break");
426 #endif /* not HISAX_DE_AOC */
428 case 2: /* return result */
429 /* if no process available handle separately */
432 l3dss1_dummy_return_result(st, id, p, nlen);
435 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
436 { /* Diversion successful */
437 free_invoke_id(st,pc->prot.dss1.invoke_id);
438 pc->prot.dss1.remote_result = 0; /* success */
439 pc->prot.dss1.invoke_id = 0;
440 pc->redir_result = pc->prot.dss1.remote_result;
441 st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
443 l3_debug(st,"return error unknown identifier");
445 case 3: /* return error */
448 { l3_debug(st, "return error nlen < 2");
453 l3_debug(st, "invoke error tag !=0x02");
459 { /* length format */
460 l3_debug(st, "invoke return errlen > 4 ");
465 if (ilen > nlen || ilen == 0)
466 { l3_debug(st, "error return ilen > nlen || ilen == 0");
471 { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
474 /* if no process available handle separately */
477 l3dss1_dummy_error_return(st, id, err_ret);
480 if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
481 { /* Deflection error */
482 free_invoke_id(st,pc->prot.dss1.invoke_id);
483 pc->prot.dss1.remote_result = err_ret; /* result */
484 pc->prot.dss1.invoke_id = 0;
485 pc->redir_result = pc->prot.dss1.remote_result;
486 st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
487 } /* Deflection error */
489 l3_debug(st,"return result unknown identifier");
492 l3_debug(st, "facility default break tag=0x%02x",cp_tag);
498 l3dss1_message(struct l3_process *pc, u_char mt)
503 if (!(skb = l3_alloc_skb(4)))
506 MsgHead(p, pc->callref, mt);
507 l3_msg(pc->st, DL_DATA | REQUEST, skb);
511 l3dss1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
518 MsgHead(p, pc->callref, mt);
525 if (!(skb = l3_alloc_skb(l)))
527 memcpy(skb_put(skb, l), tmp, l);
528 l3_msg(pc->st, DL_DATA | REQUEST, skb);
532 l3dss1_status_send(struct l3_process *pc, u_char pr, void *arg)
539 MsgHead(p, pc->callref, MT_STATUS);
544 *p++ = pc->para.cause | 0x80;
546 *p++ = IE_CALL_STATE;
548 *p++ = pc->state & 0x3f;
551 if (!(skb = l3_alloc_skb(l)))
553 memcpy(skb_put(skb, l), tmp, l);
554 l3_msg(pc->st, DL_DATA | REQUEST, skb);
558 l3dss1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
560 /* This routine is called if here was no SETUP made (checks in dss1up and in
561 * l3dss1_setup) and a RELEASE_COMPLETE have to be sent with an error code
562 * MT_STATUS_ENQUIRE in the NULL state is handled too
569 switch (pc->para.cause) {
570 case 81: /* invalid callreference */
571 case 88: /* incomp destination */
572 case 96: /* mandory IE missing */
573 case 100: /* invalid IE contents */
574 case 101: /* incompatible Callstate */
575 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
579 *p++ = pc->para.cause | 0x80;
582 printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n",
587 if (!(skb = l3_alloc_skb(l)))
589 memcpy(skb_put(skb, l), tmp, l);
590 l3_msg(pc->st, DL_DATA | REQUEST, skb);
591 dss1_release_l3_process(pc);
594 static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
595 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
597 static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
598 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
599 static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
600 IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
601 IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
602 static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
603 static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
604 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
605 static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
607 static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
608 static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
609 IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
610 static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
611 IE_SIGNAL, IE_USER_USER, -1};
612 /* a RELEASE_COMPLETE with errors don't require special actions
613 static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
615 static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
617 static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
618 static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
619 IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
620 IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
621 IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
622 IE_LLC, IE_HLC, IE_USER_USER, -1};
623 static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
624 IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
625 static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
626 IE_MANDATORY, IE_DISPLAY, -1};
627 static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
628 static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
629 static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
631 * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
632 * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
633 * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
634 * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
637 static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
638 static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
639 static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
647 struct ie_len max_ie_len[] = {
665 {IE_PACK_BINPARA, 3},
666 {IE_PACK_WINSIZE, 4},
671 {IE_CALLING_SUB, 23},
684 getmax_ie_len(u_char ie) {
686 while (max_ie_len[i].ie != -1) {
687 if (max_ie_len[i].ie == ie)
688 return(max_ie_len[i].len);
695 ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
698 while (*checklist != -1) {
699 if ((*checklist & 0xff) == ie) {
712 check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
717 int l, newpos, oldpos;
718 int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
720 u_char old_codeset = 0;
730 while ((p - skb->data) < skb->len) {
731 if ((*p & 0xf0) == 0x90) { /* shift codeset */
732 old_codeset = codeset;
738 if (pc->debug & L3_DEB_CHECK)
739 l3_debug(pc->st, "check IE shift%scodeset %d->%d",
740 codelock ? " locking ": " ", old_codeset, codeset);
744 if (!codeset) { /* only codeset 0 */
745 if ((newpos = ie_in_set(pc, *p, cl))) {
753 if (ie_in_set(pc, *p, comp_required))
767 if (!codeset && (l > getmax_ie_len(ie)))
770 if (pc->debug & L3_DEB_CHECK)
771 l3_debug(pc->st, "check IE shift back codeset %d->%d",
772 codeset, old_codeset);
773 codeset = old_codeset;
777 if (err_compr | err_ureg | err_len | err_seq) {
778 if (pc->debug & L3_DEB_CHECK)
779 l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
780 mt, err_compr, err_ureg, err_len, err_seq);
782 return(ERR_IE_COMPREHENSION);
784 return(ERR_IE_UNRECOGNIZED);
786 return(ERR_IE_LENGTH);
788 return(ERR_IE_SEQUENCE);
793 /* verify if a message type exists and contain no IE error */
795 l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
799 case MT_CALL_PROCEEDING:
801 case MT_CONNECT_ACKNOWLEDGE:
808 case MT_RELEASE_COMPLETE:
810 case MT_SETUP_ACKNOWLEDGE:
811 case MT_RESUME_ACKNOWLEDGE:
812 case MT_RESUME_REJECT:
813 case MT_SUSPEND_ACKNOWLEDGE:
814 case MT_SUSPEND_REJECT:
815 case MT_USER_INFORMATION:
817 case MT_RESTART_ACKNOWLEDGE:
818 case MT_CONGESTION_CONTROL:
820 case MT_STATUS_ENQUIRY:
821 if (pc->debug & L3_DEB_CHECK)
822 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) OK", mt);
824 case MT_RESUME: /* RESUME only in user->net */
825 case MT_SUSPEND: /* SUSPEND only in user->net */
827 if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
828 l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt);
830 l3dss1_status_send(pc, 0, NULL);
837 l3dss1_std_ie_err(struct l3_process *pc, int ret) {
839 if (pc->debug & L3_DEB_CHECK)
840 l3_debug(pc->st, "check_infoelements ret %d", ret);
844 case ERR_IE_COMPREHENSION:
846 l3dss1_status_send(pc, 0, NULL);
848 case ERR_IE_UNRECOGNIZED:
850 l3dss1_status_send(pc, 0, NULL);
853 pc->para.cause = 100;
854 l3dss1_status_send(pc, 0, NULL);
856 case ERR_IE_SEQUENCE:
863 l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
867 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
869 if (*p != 1) { /* len for BRI = 1 */
870 if (pc->debug & L3_DEB_WARN)
871 l3_debug(pc->st, "wrong chid len %d", *p);
875 if (*p & 0x60) { /* only base rate interface */
876 if (pc->debug & L3_DEB_WARN)
877 l3_debug(pc->st, "wrong chid %x", *p);
886 l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
893 if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
904 if (l && !(pc->para.loc & 0x80)) {
906 p++; /* skip recommendation */
909 pc->para.cause = *p++;
911 if (!(pc->para.cause & 0x80))
916 pc->para.diag[i++] = *p++;
925 l3dss1_msg_with_uus(struct l3_process *pc, u_char cmd)
932 MsgHead(p, pc->callref, cmd);
934 if (pc->prot.dss1.uus1_data[0])
935 { *p++ = IE_USER_USER; /* UUS info element */
936 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
937 *p++ = 0x04; /* IA5 chars */
938 strcpy(p,pc->prot.dss1.uus1_data);
939 p += strlen(pc->prot.dss1.uus1_data);
940 pc->prot.dss1.uus1_data[0] = '\0';
944 if (!(skb = l3_alloc_skb(l)))
946 memcpy(skb_put(skb, l), tmp, l);
947 l3_msg(pc->st, DL_DATA | REQUEST, skb);
948 } /* l3dss1_msg_with_uus */
951 l3dss1_release_req(struct l3_process *pc, u_char pr, void *arg)
955 if (!pc->prot.dss1.uus1_data[0])
956 l3dss1_message(pc, MT_RELEASE);
958 l3dss1_msg_with_uus(pc, MT_RELEASE);
959 L3AddTimer(&pc->timer, T308, CC_T308_1);
963 l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
965 struct sk_buff *skb = arg;
968 if ((ret = l3dss1_get_cause(pc, skb))>0) {
969 if (pc->debug & L3_DEB_WARN)
970 l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
972 pc->para.cause = NO_CAUSE;
975 pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
976 dss1_release_l3_process(pc);
979 #ifdef EXT_BEARER_CAPS
982 EncodeASyncParams(u_char * p, u_char si2)
983 { // 7c 06 88 90 21 42 00 bb
986 p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
988 if (si2 & 32) // 7 data bits
995 if (si2 & 16) // 2 stop bits
1002 if (si2 & 8) // even parity
1009 switch (si2 & 0x07) {
1011 p[0] = 66; // 1200 bit/s
1015 p[0] = 88; // 1200/75 bit/s
1019 p[0] = 87; // 75/1200 bit/s
1023 p[0] = 67; // 2400 bit/s
1027 p[0] = 69; // 4800 bit/s
1031 p[0] = 72; // 9600 bit/s
1035 p[0] = 73; // 14400 bit/s
1039 p[0] = 75; // 19200 bit/s
1047 EncodeSyncParams(u_char si2, u_char ai)
1052 return ai + 2; // 1200 bit/s
1055 return ai + 24; // 1200/75 bit/s
1058 return ai + 23; // 75/1200 bit/s
1061 return ai + 3; // 2400 bit/s
1064 return ai + 5; // 4800 bit/s
1067 return ai + 8; // 9600 bit/s
1070 return ai + 9; // 14400 bit/s
1073 return ai + 11; // 19200 bit/s
1076 return ai + 14; // 48000 bit/s
1079 return ai + 15; // 56000 bit/s
1082 return ai + 40; // negotiate bit/s
1092 DecodeASyncParams(u_char si2, u_char * p)
1097 case 66: // 1200 bit/s
1099 break; // si2 don't change
1101 case 88: // 1200/75 bit/s
1105 case 87: // 75/1200 bit/s
1109 case 67: // 2400 bit/s
1113 case 69: // 4800 bit/s
1117 case 72: // 9600 bit/s
1121 case 73: // 14400 bit/s
1125 case 75: // 19200 bit/s
1132 if ((info & 16) && (!(info & 8))) // 7 data bits
1134 si2 += 32; // else 8 data bits
1136 if ((info & 96) == 96) // 2 stop bits
1138 si2 += 16; // else 1 stop bit
1140 if ((info & 2) && (!(info & 1))) // even parity
1142 si2 += 8; // else no parity
1149 DecodeSyncParams(u_char si2, u_char info)
1153 case 40: // bit/s negotiation failed ai := 165 not 175!
1156 case 15: // 56000 bit/s failed, ai := 0 not 169 !
1159 case 14: // 48000 bit/s
1162 case 11: // 19200 bit/s
1165 case 9: // 14400 bit/s
1168 case 8: // 9600 bit/s
1171 case 5: // 4800 bit/s
1174 case 3: // 2400 bit/s
1177 case 23: // 75/1200 bit/s
1180 case 24: // 1200/75 bit/s
1183 default: // 1200 bit/s
1190 DecodeSI2(struct sk_buff *skb)
1192 u_char *p; //, *pend=skb->data + skb->len;
1194 if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
1195 switch (p[4] & 0x0f) {
1197 if (p[1] == 0x04) // sync. Bitratenadaption
1199 return DecodeSyncParams(160, p[5]); // V.110/X.30
1201 else if (p[1] == 0x06) // async. Bitratenadaption
1203 return DecodeASyncParams(192, p); // V.110/X.30
1206 case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
1208 return DecodeSyncParams(176, p[5]); // V.120
1219 l3dss1_setup_req(struct l3_process *pc, u_char pr,
1222 struct sk_buff *skb;
1228 u_char screen = 0x80;
1235 MsgHead(p, pc->callref, MT_SETUP);
1237 teln = pc->para.setup.phone;
1238 #ifndef CONFIG_HISAX_NO_KEYPAD
1239 send_keypad = (strchr(teln,'*') || strchr(teln,'#')) ? 1 : 0;
1243 #ifndef CONFIG_HISAX_NO_SENDCOMPLETE
1245 *p++ = 0xa1; /* complete indicator */
1248 * Set Bearer Capability, Map info from 1TR6-convention to EDSS1
1250 switch (pc->para.setup.si1) {
1251 case 1: /* Telephony */
1253 *p++ = 0x3; /* Length */
1254 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1255 *p++ = 0x90; /* Circuit-Mode 64kbps */
1256 *p++ = 0xa3; /* A-Law Audio */
1258 case 5: /* Datatransmission 64k, BTX */
1259 case 7: /* Datatransmission 64k */
1262 *p++ = 0x2; /* Length */
1263 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1264 *p++ = 0x90; /* Circuit-Mode 64kbps */
1270 *p++ = strlen(teln);
1272 *p++ = (*teln++) & 0x7F;
1276 * What about info2? Mapping to High-Layer-Compatibility?
1278 if ((*teln) && (!send_keypad)) {
1279 /* parse number for special things */
1280 if (!isdigit(*teln)) {
1281 switch (0x5f & *teln) {
1300 if (pc->debug & L3_DEB_WARN)
1301 l3_debug(pc->st, "Wrong MSN Code");
1308 *p++ = IE_CHANNEL_ID;
1312 msn = pc->para.setup.eazmsn;
1323 *p++ = IE_CALLING_PN;
1324 *p++ = strlen(msn) + (screen ? 2 : 1);
1325 /* Classify as AnyPref. */
1327 *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
1330 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1332 *p++ = *msn++ & 0x7f;
1336 *p++ = IE_CALLING_SUB;
1337 *p++ = strlen(sub) + 2;
1338 *p++ = 0x80; /* NSAP coded */
1339 *p++ = 0x50; /* local IDI format */
1341 *p++ = *sub++ & 0x7f;
1354 *p++ = IE_CALLED_PN;
1355 *p++ = strlen(teln) + 1;
1356 /* Classify as AnyPref. */
1357 *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
1359 *p++ = *teln++ & 0x7f;
1363 *p++ = IE_CALLED_SUB;
1364 *p++ = strlen(sub) + 2;
1365 *p++ = 0x80; /* NSAP coded */
1366 *p++ = 0x50; /* local IDI format */
1368 *p++ = *sub++ & 0x7f;
1371 #ifdef EXT_BEARER_CAPS
1372 if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
1379 *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
1380 } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
1387 *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
1389 } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
1396 p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
1397 #ifndef CONFIG_HISAX_NO_LLC
1399 switch (pc->para.setup.si1) {
1400 case 1: /* Telephony */
1402 *p++ = 0x3; /* Length */
1403 *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
1404 *p++ = 0x90; /* Circuit-Mode 64kbps */
1405 *p++ = 0xa3; /* A-Law Audio */
1407 case 5: /* Datatransmission 64k, BTX */
1408 case 7: /* Datatransmission 64k */
1411 *p++ = 0x2; /* Length */
1412 *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
1413 *p++ = 0x90; /* Circuit-Mode 64kbps */
1420 if (!(skb = l3_alloc_skb(l)))
1422 memcpy(skb_put(skb, l), tmp, l);
1423 L3DelTimer(&pc->timer);
1424 L3AddTimer(&pc->timer, T303, CC_T303);
1426 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1430 l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg)
1432 struct sk_buff *skb = arg;
1435 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1436 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1437 if (pc->debug & L3_DEB_WARN)
1438 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1439 pc->para.cause = 100;
1440 l3dss1_status_send(pc, pr, NULL);
1443 pc->para.bchannel = id;
1444 } else if (1 == pc->state) {
1445 if (pc->debug & L3_DEB_WARN)
1446 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1448 pc->para.cause = 96;
1450 pc->para.cause = 100;
1451 l3dss1_status_send(pc, pr, NULL);
1454 /* Now we are on none mandatory IEs */
1455 ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
1456 if (ERR_IE_COMPREHENSION == ret) {
1457 l3dss1_std_ie_err(pc, ret);
1460 L3DelTimer(&pc->timer);
1462 L3AddTimer(&pc->timer, T310, CC_T310);
1463 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1464 l3dss1_std_ie_err(pc, ret);
1465 pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
1469 l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
1471 struct sk_buff *skb = arg;
1474 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1475 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
1476 if (pc->debug & L3_DEB_WARN)
1477 l3_debug(pc->st, "setup answer with wrong chid %x", id);
1478 pc->para.cause = 100;
1479 l3dss1_status_send(pc, pr, NULL);
1482 pc->para.bchannel = id;
1484 if (pc->debug & L3_DEB_WARN)
1485 l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
1487 pc->para.cause = 96;
1489 pc->para.cause = 100;
1490 l3dss1_status_send(pc, pr, NULL);
1493 /* Now we are on none mandatory IEs */
1494 ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
1495 if (ERR_IE_COMPREHENSION == ret) {
1496 l3dss1_std_ie_err(pc, ret);
1499 L3DelTimer(&pc->timer);
1501 L3AddTimer(&pc->timer, T304, CC_T304);
1502 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
1503 l3dss1_std_ie_err(pc, ret);
1504 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
1508 l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg)
1510 struct sk_buff *skb = arg;
1516 if ((ret = l3dss1_get_cause(pc, skb))) {
1517 if (pc->debug & L3_DEB_WARN)
1518 l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
1524 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
1525 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1526 ret = check_infoelements(pc, skb, ie_DISCONNECT);
1527 if (ERR_IE_COMPREHENSION == ret)
1529 else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
1536 pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
1538 l3dss1_release_req(pc, pr, NULL);
1540 l3dss1_message_cause(pc, MT_RELEASE, cause);
1541 L3AddTimer(&pc->timer, T308, CC_T308_1);
1546 l3dss1_connect(struct l3_process *pc, u_char pr, void *arg)
1548 struct sk_buff *skb = arg;
1551 ret = check_infoelements(pc, skb, ie_CONNECT);
1552 if (ERR_IE_COMPREHENSION == ret) {
1553 l3dss1_std_ie_err(pc, ret);
1556 L3DelTimer(&pc->timer); /* T310 */
1558 pc->para.chargeinfo = 0;
1559 /* here should inserted COLP handling KKe */
1561 l3dss1_std_ie_err(pc, ret);
1562 pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
1566 l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg)
1568 struct sk_buff *skb = arg;
1571 ret = check_infoelements(pc, skb, ie_ALERTING);
1572 if (ERR_IE_COMPREHENSION == ret) {
1573 l3dss1_std_ie_err(pc, ret);
1576 L3DelTimer(&pc->timer); /* T304 */
1579 l3dss1_std_ie_err(pc, ret);
1580 pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
1584 l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
1589 struct sk_buff *skb = arg;
1594 * Bearer Capabilities
1597 /* only the first occurence 'll be detected ! */
1598 if ((p = findie(p, skb->len, 0x04, 0))) {
1599 if ((p[1] < 2) || (p[1] > 11))
1602 pc->para.setup.si2 = 0;
1603 switch (p[2] & 0x7f) {
1604 case 0x00: /* Speech */
1605 case 0x10: /* 3.1 Khz audio */
1606 pc->para.setup.si1 = 1;
1608 case 0x08: /* Unrestricted digital information */
1609 pc->para.setup.si1 = 7;
1610 /* JIM, 05.11.97 I wanna set service indicator 2 */
1611 #ifdef EXT_BEARER_CAPS
1612 pc->para.setup.si2 = DecodeSI2(skb);
1615 case 0x09: /* Restricted digital information */
1616 pc->para.setup.si1 = 2;
1619 /* Unrestr. digital information with
1620 * tones/announcements ( or 7 kHz audio
1622 pc->para.setup.si1 = 3;
1624 case 0x18: /* Video */
1625 pc->para.setup.si1 = 4;
1631 switch (p[3] & 0x7f) {
1632 case 0x40: /* packed mode */
1633 pc->para.setup.si1 = 8;
1635 case 0x10: /* 64 kbit */
1636 case 0x11: /* 2*64 kbit */
1637 case 0x13: /* 384 kbit */
1638 case 0x15: /* 1536 kbit */
1639 case 0x17: /* 1920 kbit */
1640 pc->para.moderate = p[3] & 0x7f;
1647 if (pc->debug & L3_DEB_SI)
1648 l3_debug(pc->st, "SI=%d, AI=%d",
1649 pc->para.setup.si1, pc->para.setup.si2);
1651 if (pc->debug & L3_DEB_WARN)
1652 l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
1654 pc->para.cause = 100;
1655 l3dss1_msg_without_setup(pc, pr, NULL);
1659 if (pc->debug & L3_DEB_WARN)
1660 l3_debug(pc->st, "setup without bearer capabilities");
1661 /* ETS 300-104 1.3.3 */
1662 pc->para.cause = 96;
1663 l3dss1_msg_without_setup(pc, pr, NULL);
1667 * Channel Identification
1669 if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
1670 if ((pc->para.bchannel = id)) {
1671 if ((3 == id) && (0x10 == pc->para.moderate)) {
1672 if (pc->debug & L3_DEB_WARN)
1673 l3_debug(pc->st, "setup with wrong chid %x",
1675 pc->para.cause = 100;
1676 l3dss1_msg_without_setup(pc, pr, NULL);
1681 { if (pc->debug & L3_DEB_WARN)
1682 l3_debug(pc->st, "setup without bchannel, call waiting");
1686 if (pc->debug & L3_DEB_WARN)
1687 l3_debug(pc->st, "setup with wrong chid ret %d", id);
1689 pc->para.cause = 96;
1691 pc->para.cause = 100;
1692 l3dss1_msg_without_setup(pc, pr, NULL);
1695 /* Now we are on none mandatory IEs */
1696 err = check_infoelements(pc, skb, ie_SETUP);
1697 if (ERR_IE_COMPREHENSION == err) {
1698 pc->para.cause = 96;
1699 l3dss1_msg_without_setup(pc, pr, NULL);
1703 if ((p = findie(p, skb->len, 0x70, 0)))
1704 iecpy(pc->para.setup.eazmsn, p, 1);
1706 pc->para.setup.eazmsn[0] = 0;
1709 if ((p = findie(p, skb->len, 0x71, 0))) {
1710 /* Called party subaddress */
1711 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1713 iecpy(&tmp[1], p, 2);
1714 strcat(pc->para.setup.eazmsn, tmp);
1715 } else if (pc->debug & L3_DEB_WARN)
1716 l3_debug(pc->st, "wrong called subaddress");
1719 if ((p = findie(p, skb->len, 0x6c, 0))) {
1720 pc->para.setup.plan = p[2];
1722 iecpy(pc->para.setup.phone, p, 1);
1723 pc->para.setup.screen = 0;
1725 iecpy(pc->para.setup.phone, p, 2);
1726 pc->para.setup.screen = p[3];
1729 pc->para.setup.phone[0] = 0;
1730 pc->para.setup.plan = 0;
1731 pc->para.setup.screen = 0;
1734 if ((p = findie(p, skb->len, 0x6d, 0))) {
1735 /* Calling party subaddress */
1736 if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
1738 iecpy(&tmp[1], p, 2);
1739 strcat(pc->para.setup.phone, tmp);
1740 } else if (pc->debug & L3_DEB_WARN)
1741 l3_debug(pc->st, "wrong calling subaddress");
1744 if (err) /* STATUS for none mandatory IE errors after actions are taken */
1745 l3dss1_std_ie_err(pc, err);
1746 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
1750 l3dss1_reset(struct l3_process *pc, u_char pr, void *arg)
1752 dss1_release_l3_process(pc);
1756 l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
1758 struct sk_buff *skb;
1764 if (pc->para.cause != NO_CAUSE)
1765 cause = pc->para.cause;
1769 MsgHead(p, pc->callref, MT_DISCONNECT);
1774 *p++ = cause | 0x80;
1776 if (pc->prot.dss1.uus1_data[0])
1777 { *p++ = IE_USER_USER; /* UUS info element */
1778 *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
1779 *p++ = 0x04; /* IA5 chars */
1780 strcpy(p,pc->prot.dss1.uus1_data);
1781 p += strlen(pc->prot.dss1.uus1_data);
1782 pc->prot.dss1.uus1_data[0] = '\0';
1786 if (!(skb = l3_alloc_skb(l)))
1788 memcpy(skb_put(skb, l), tmp, l);
1790 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1791 L3AddTimer(&pc->timer, T305, CC_T305);
1795 l3dss1_setup_rsp(struct l3_process *pc, u_char pr,
1798 if (!pc->para.bchannel)
1799 { if (pc->debug & L3_DEB_WARN)
1800 l3_debug(pc->st, "D-chan connect for waiting call");
1801 l3dss1_disconnect_req(pc, pr, arg);
1805 l3dss1_message(pc, MT_CONNECT);
1806 L3DelTimer(&pc->timer);
1807 L3AddTimer(&pc->timer, T313, CC_T313);
1811 l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
1813 struct sk_buff *skb = arg;
1816 ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
1817 if (ERR_IE_COMPREHENSION == ret) {
1818 l3dss1_std_ie_err(pc, ret);
1822 L3DelTimer(&pc->timer);
1824 l3dss1_std_ie_err(pc, ret);
1825 pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
1829 l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg)
1831 struct sk_buff *skb;
1837 if (pc->para.cause != NO_CAUSE)
1838 cause = pc->para.cause;
1840 MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
1845 *p++ = cause | 0x80;
1848 if (!(skb = l3_alloc_skb(l)))
1850 memcpy(skb_put(skb, l), tmp, l);
1851 l3_msg(pc->st, DL_DATA | REQUEST, skb);
1852 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1854 dss1_release_l3_process(pc);
1858 l3dss1_release(struct l3_process *pc, u_char pr, void *arg)
1860 struct sk_buff *skb = arg;
1865 if ((ret = l3dss1_get_cause(pc, skb))>0) {
1866 if (pc->debug & L3_DEB_WARN)
1867 l3_debug(pc->st, "REL get_cause ret(%d)", ret);
1869 pc->para.cause = NO_CAUSE;
1870 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
1871 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
1873 if ((ret<0) && (pc->state != 11))
1877 ret = check_infoelements(pc, skb, ie_RELEASE);
1878 if (ERR_IE_COMPREHENSION == ret)
1880 else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
1883 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
1885 l3dss1_message(pc, MT_RELEASE_COMPLETE);
1886 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
1888 dss1_release_l3_process(pc);
1892 l3dss1_alert_req(struct l3_process *pc, u_char pr,
1896 if (!pc->prot.dss1.uus1_data[0])
1897 l3dss1_message(pc, MT_ALERTING);
1899 l3dss1_msg_with_uus(pc, MT_ALERTING);
1903 l3dss1_proceed_req(struct l3_process *pc, u_char pr,
1907 l3dss1_message(pc, MT_CALL_PROCEEDING);
1908 pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
1912 l3dss1_setup_ack_req(struct l3_process *pc, u_char pr,
1916 L3DelTimer(&pc->timer);
1917 L3AddTimer(&pc->timer, T302, CC_T302);
1918 l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
1921 /********************************************/
1922 /* deliver a incoming display message to HL */
1923 /********************************************/
1925 l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
1928 struct IsdnCardState *cs;
1931 if (*infp++ != IE_DISPLAY) return;
1932 if ((len = *infp++) > 80) return; /* total length <= 82 */
1933 if (!pc->chan) return;
1935 p = ic.parm.display;
1939 ic.command = ISDN_STAT_DISPLAY;
1940 cs = pc->st->l1.hardware;
1941 ic.driver = cs->myid;
1942 ic.arg = pc->chan->chan;
1943 cs->iif.statcallb(&ic);
1944 } /* l3dss1_deliver_display */
1948 l3dss1_progress(struct l3_process *pc, u_char pr, void *arg)
1950 struct sk_buff *skb = arg;
1954 if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
1957 pc->para.cause = 100;
1958 } else if (!(p[2] & 0x70)) {
1976 pc->para.cause = 100;
1982 pc->para.cause = 100;
1987 pc->para.cause = 96;
1991 if (pc->debug & L3_DEB_WARN)
1992 l3_debug(pc->st, "progress error %d", err);
1993 l3dss1_status_send(pc, pr, NULL);
1996 /* Now we are on none mandatory IEs */
1997 err = check_infoelements(pc, skb, ie_PROGRESS);
1999 l3dss1_std_ie_err(pc, err);
2000 if (ERR_IE_COMPREHENSION != err)
2001 pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
2005 l3dss1_notify(struct l3_process *pc, u_char pr, void *arg)
2007 struct sk_buff *skb = arg;
2011 if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
2014 pc->para.cause = 100;
2022 pc->para.cause = 100;
2028 pc->para.cause = 96;
2032 if (pc->debug & L3_DEB_WARN)
2033 l3_debug(pc->st, "notify error %d", err);
2034 l3dss1_status_send(pc, pr, NULL);
2037 /* Now we are on none mandatory IEs */
2038 err = check_infoelements(pc, skb, ie_NOTIFY);
2040 l3dss1_std_ie_err(pc, err);
2041 if (ERR_IE_COMPREHENSION != err)
2042 pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
2046 l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg)
2049 struct sk_buff *skb = arg;
2051 ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
2052 l3dss1_std_ie_err(pc, ret);
2053 pc->para.cause = 30; /* response to STATUS_ENQUIRY */
2054 l3dss1_status_send(pc, pr, NULL);
2058 l3dss1_information(struct l3_process *pc, u_char pr, void *arg)
2061 struct sk_buff *skb = arg;
2065 ret = check_infoelements(pc, skb, ie_INFORMATION);
2067 l3dss1_std_ie_err(pc, ret);
2068 if (pc->state == 25) { /* overlap receiving */
2069 L3DelTimer(&pc->timer);
2071 if ((p = findie(p, skb->len, 0x70, 0))) {
2073 strcat(pc->para.setup.eazmsn, tmp);
2074 pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
2076 L3AddTimer(&pc->timer, T302, CC_T302);
2080 /******************************/
2081 /* handle deflection requests */
2082 /******************************/
2083 static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg)
2085 struct sk_buff *skb;
2089 u_char len_phone = 0;
2094 strcpy(pc->prot.dss1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
2095 if (!pc->chan->setup.phone[0])
2096 { pc->para.cause = -1;
2097 l3dss1_disconnect_req(pc,pr,arg); /* disconnect immediately */
2101 if (pc->prot.dss1.invoke_id)
2102 free_invoke_id(pc->st,pc->prot.dss1.invoke_id);
2104 if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
2107 MsgHead(p, pc->callref, MT_FACILITY);
2109 for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
2110 if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
2112 *p++ = 0x1c; /* Facility info element */
2113 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
2114 *p++ = 0x91; /* remote operations protocol */
2115 *p++ = 0xa1; /* invoke component */
2117 *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
2118 *p++ = 0x02; /* invoke id tag, integer */
2119 *p++ = 0x01; /* length */
2120 *p++ = pc->prot.dss1.invoke_id; /* invoke id */
2121 *p++ = 0x02; /* operation value tag, integer */
2122 *p++ = 0x01; /* length */
2123 *p++ = 0x0D; /* Call Deflect */
2125 *p++ = 0x30; /* sequence phone number */
2126 *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
2128 *p++ = 0x30; /* Deflected to UserNumber */
2129 *p++ = len_phone+2+len_sub; /* length */
2130 *p++ = 0x80; /* NumberDigits */
2131 *p++ = len_phone; /* length */
2132 for (l = 0; l < len_phone; l++)
2133 *p++ = pc->chan->setup.phone[l];
2136 { *p++ = 0x04; /* called party subaddress */
2138 while (*subp) *p++ = *subp++;
2141 *p++ = 0x01; /* screening identifier */
2143 *p++ = pc->chan->setup.screen;
2146 if (!(skb = l3_alloc_skb(l))) return;
2147 memcpy(skb_put(skb, l), tmp, l);
2149 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2150 } /* l3dss1_redir_req */
2152 /********************************************/
2153 /* handle deflection request in early state */
2154 /********************************************/
2155 static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
2157 l3dss1_proceed_req(pc,pr,arg);
2158 l3dss1_redir_req(pc,pr,arg);
2159 } /* l3dss1_redir_req_early */
2161 /***********************************************/
2162 /* handle special commands for this protocol. */
2163 /* Examples are call independant services like */
2164 /* remote operations with dummy callref. */
2165 /***********************************************/
2166 static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
2171 struct sk_buff *skb;
2172 struct l3_process *pc = NULL;
2175 { case DSS1_CMD_INVOKE:
2176 if (ic->parm.dss1_io.datalen < 0) return(-2); /* invalid parameter */
2178 for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
2179 i = i >> 8; /* add one byte */
2180 l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
2182 return(-2); /* too long */
2184 if (!(id = new_invoke_id(st)))
2185 return(0); /* first get a invoke id -> return if no available */
2188 MsgHead(p, i, MT_FACILITY); /* build message head */
2189 *p++ = 0x1C; /* Facility IE */
2190 *p++ = l; /* length of ie */
2191 *p++ = 0x91; /* remote operations */
2192 *p++ = 0xA1; /* invoke */
2193 *p++ = l - 3; /* length of invoke */
2194 *p++ = 0x02; /* invoke id tag */
2195 *p++ = 0x01; /* length is 1 */
2196 *p++ = id; /* invoke id */
2197 *p++ = 0x02; /* operation */
2198 *p++ = proc_len; /* length of operation */
2200 for (i = proc_len; i; i--)
2201 *p++ = (ic->parm.dss1_io.proc >> (i-1)) & 0xFF;
2202 memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
2203 l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
2205 if (ic->parm.dss1_io.timeout > 0)
2206 if (!(pc = dss1_new_l3_process(st, -1)))
2207 { free_invoke_id(st, id);
2210 pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
2211 pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
2213 if (!(skb = l3_alloc_skb(l)))
2214 { free_invoke_id(st, id);
2215 if (pc) dss1_release_l3_process(pc);
2218 memcpy(skb_put(skb, l), temp, l);
2221 { pc->prot.dss1.invoke_id = id; /* remember id */
2222 L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
2225 l3_msg(st, DL_DATA | REQUEST, skb);
2226 ic->parm.dss1_io.hl_id = id; /* return id */
2229 case DSS1_CMD_INVOKE_ABORT:
2230 if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
2231 { L3DelTimer(&pc->timer); /* remove timer */
2232 dss1_release_l3_process(pc);
2236 { l3_debug(st, "l3dss1_cmd_global abort unknown id");
2242 l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
2244 } /* switch ic-> arg */
2246 } /* l3dss1_cmd_global */
2249 l3dss1_io_timer(struct l3_process *pc)
2251 struct IsdnCardState *cs = pc->st->l1.hardware;
2253 L3DelTimer(&pc->timer); /* remove timer */
2255 ic.driver = cs->myid;
2256 ic.command = ISDN_STAT_PROT;
2257 ic.arg = DSS1_STAT_INVOKE_ERR;
2258 ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
2259 ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
2260 ic.parm.dss1_io.proc = pc->prot.dss1.proc;
2261 ic.parm.dss1_io.timeout= -1;
2262 ic.parm.dss1_io.datalen = 0;
2263 ic.parm.dss1_io.data = NULL;
2264 free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
2265 pc->prot.dss1.invoke_id = 0; /* reset id */
2267 cs->iif.statcallb(&ic);
2269 dss1_release_l3_process(pc);
2270 } /* l3dss1_io_timer */
2273 l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg)
2276 struct sk_buff *skb = arg;
2280 if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
2285 if (callState == 0) {
2286 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
2287 * set down layer 3 without sending any message
2289 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2291 dss1_release_l3_process(pc);
2293 pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
2298 l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg)
2303 l3dss1_t302(struct l3_process *pc, u_char pr, void *arg)
2305 L3DelTimer(&pc->timer);
2307 pc->para.cause = 28; /* invalid number */
2308 l3dss1_disconnect_req(pc, pr, NULL);
2309 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2313 l3dss1_t303(struct l3_process *pc, u_char pr, void *arg)
2317 L3DelTimer(&pc->timer);
2318 l3dss1_setup_req(pc, pr, arg);
2320 L3DelTimer(&pc->timer);
2321 l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
2322 pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
2323 dss1_release_l3_process(pc);
2328 l3dss1_t304(struct l3_process *pc, u_char pr, void *arg)
2330 L3DelTimer(&pc->timer);
2332 pc->para.cause = 102;
2333 l3dss1_disconnect_req(pc, pr, NULL);
2334 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2339 l3dss1_t305(struct l3_process *pc, u_char pr, void *arg)
2344 struct sk_buff *skb;
2347 L3DelTimer(&pc->timer);
2348 if (pc->para.cause != NO_CAUSE)
2349 cause = pc->para.cause;
2351 MsgHead(p, pc->callref, MT_RELEASE);
2356 *p++ = cause | 0x80;
2359 if (!(skb = l3_alloc_skb(l)))
2361 memcpy(skb_put(skb, l), tmp, l);
2363 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2364 L3AddTimer(&pc->timer, T308, CC_T308_1);
2368 l3dss1_t310(struct l3_process *pc, u_char pr, void *arg)
2370 L3DelTimer(&pc->timer);
2372 pc->para.cause = 102;
2373 l3dss1_disconnect_req(pc, pr, NULL);
2374 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2378 l3dss1_t313(struct l3_process *pc, u_char pr, void *arg)
2380 L3DelTimer(&pc->timer);
2382 pc->para.cause = 102;
2383 l3dss1_disconnect_req(pc, pr, NULL);
2384 pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
2388 l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg)
2391 L3DelTimer(&pc->timer);
2392 l3dss1_message(pc, MT_RELEASE);
2393 L3AddTimer(&pc->timer, T308, CC_T308_2);
2397 l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg)
2399 L3DelTimer(&pc->timer);
2400 pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
2401 dss1_release_l3_process(pc);
2405 l3dss1_t318(struct l3_process *pc, u_char pr, void *arg)
2407 L3DelTimer(&pc->timer);
2408 pc->para.cause = 102; /* Timer expiry */
2409 pc->para.loc = 0; /* local */
2410 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2412 l3dss1_message(pc, MT_RELEASE);
2413 L3AddTimer(&pc->timer, T308, CC_T308_1);
2417 l3dss1_t319(struct l3_process *pc, u_char pr, void *arg)
2419 L3DelTimer(&pc->timer);
2420 pc->para.cause = 102; /* Timer expiry */
2421 pc->para.loc = 0; /* local */
2422 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2427 l3dss1_restart(struct l3_process *pc, u_char pr, void *arg)
2429 L3DelTimer(&pc->timer);
2430 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2431 dss1_release_l3_process(pc);
2435 l3dss1_status(struct l3_process *pc, u_char pr, void *arg)
2438 struct sk_buff *skb = arg;
2440 u_char cause = 0, callState = 0;
2442 if ((ret = l3dss1_get_cause(pc, skb))) {
2443 if (pc->debug & L3_DEB_WARN)
2444 l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
2450 if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
2454 if (!ie_in_set(pc, *p, l3_valid_states))
2460 if (!cause) { /* no error before */
2461 ret = check_infoelements(pc, skb, ie_STATUS);
2462 if (ERR_IE_COMPREHENSION == ret)
2464 else if (ERR_IE_UNRECOGNIZED == ret)
2470 if (pc->debug & L3_DEB_WARN)
2471 l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
2472 tmp = pc->para.cause;
2473 pc->para.cause = cause;
2474 l3dss1_status_send(pc, 0, NULL);
2476 pc->para.cause = tmp;
2480 cause = pc->para.cause;
2481 if (((cause & 0x7f) == 111) && (callState == 0)) {
2482 /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
2483 * if received MT_STATUS with cause == 111 and call
2484 * state == 0, then we must set down layer 3
2486 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2488 dss1_release_l3_process(pc);
2493 l3dss1_facility(struct l3_process *pc, u_char pr, void *arg)
2495 struct sk_buff *skb = arg;
2498 ret = check_infoelements(pc, skb, ie_FACILITY);
2499 l3dss1_std_ie_err(pc, ret);
2502 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
2503 l3dss1_parse_facility(pc->st, pc, pc->callref, p);
2508 l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
2510 struct sk_buff *skb;
2514 u_char *msg = pc->chan->setup.phone;
2516 MsgHead(p, pc->callref, MT_SUSPEND);
2518 if (l && (l <= 10)) { /* Max length 10 octets */
2521 for (i = 0; i < l; i++)
2524 l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
2528 if (!(skb = l3_alloc_skb(l)))
2530 memcpy(skb_put(skb, l), tmp, l);
2531 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2533 L3AddTimer(&pc->timer, T319, CC_T319);
2537 l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
2539 struct sk_buff *skb = arg;
2542 L3DelTimer(&pc->timer);
2544 pc->para.cause = NO_CAUSE;
2545 pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
2546 /* We don't handle suspend_ack for IE errors now */
2547 if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
2548 if (pc->debug & L3_DEB_WARN)
2549 l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
2550 dss1_release_l3_process(pc);
2554 l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
2556 struct sk_buff *skb = arg;
2559 if ((ret = l3dss1_get_cause(pc, skb))) {
2560 if (pc->debug & L3_DEB_WARN)
2561 l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
2563 pc->para.cause = 96;
2565 pc->para.cause = 100;
2566 l3dss1_status_send(pc, pr, NULL);
2569 ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
2570 if (ERR_IE_COMPREHENSION == ret) {
2571 l3dss1_std_ie_err(pc, ret);
2574 L3DelTimer(&pc->timer);
2575 pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
2577 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2578 l3dss1_std_ie_err(pc, ret);
2582 l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg)
2584 struct sk_buff *skb;
2588 u_char *msg = pc->para.setup.phone;
2590 MsgHead(p, pc->callref, MT_RESUME);
2593 if (l && (l <= 10)) { /* Max length 10 octets */
2596 for (i = 0; i < l; i++)
2599 l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
2603 if (!(skb = l3_alloc_skb(l)))
2605 memcpy(skb_put(skb, l), tmp, l);
2606 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2608 L3AddTimer(&pc->timer, T318, CC_T318);
2612 l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
2614 struct sk_buff *skb = arg;
2617 if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
2618 if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
2619 if (pc->debug & L3_DEB_WARN)
2620 l3_debug(pc->st, "resume ack with wrong chid %x", id);
2621 pc->para.cause = 100;
2622 l3dss1_status_send(pc, pr, NULL);
2625 pc->para.bchannel = id;
2626 } else if (1 == pc->state) {
2627 if (pc->debug & L3_DEB_WARN)
2628 l3_debug(pc->st, "resume ack without chid (ret %d)", id);
2629 pc->para.cause = 96;
2630 l3dss1_status_send(pc, pr, NULL);
2633 ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
2634 if (ERR_IE_COMPREHENSION == ret) {
2635 l3dss1_std_ie_err(pc, ret);
2638 L3DelTimer(&pc->timer);
2639 pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
2641 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2642 l3dss1_std_ie_err(pc, ret);
2646 l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
2648 struct sk_buff *skb = arg;
2651 if ((ret = l3dss1_get_cause(pc, skb))) {
2652 if (pc->debug & L3_DEB_WARN)
2653 l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
2655 pc->para.cause = 96;
2657 pc->para.cause = 100;
2658 l3dss1_status_send(pc, pr, NULL);
2661 ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
2662 if (ERR_IE_COMPREHENSION == ret) {
2663 l3dss1_std_ie_err(pc, ret);
2666 L3DelTimer(&pc->timer);
2667 pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
2669 if (ret) /* STATUS for none mandatory IE errors after actions are taken */
2670 l3dss1_std_ie_err(pc, ret);
2671 dss1_release_l3_process(pc);
2675 l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg)
2679 u_char ri, ch = 0, chan = 0;
2681 struct sk_buff *skb = arg;
2682 struct l3_process *up;
2685 L3DelTimer(&pc->timer);
2687 if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
2689 l3_debug(pc->st, "Restart %x", ri);
2691 l3_debug(pc->st, "Restart without restart IE");
2695 if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
2698 if (pc->st->l3.debug)
2699 l3_debug(pc->st, "Restart for channel %d", chan);
2702 up = pc->st->l3.proc;
2705 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2706 else if (up->para.bchannel == chan)
2707 up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
2711 MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
2713 *p++ = IE_CHANNEL_ID;
2717 *p++ = 0x79; /* RESTART Ind */
2721 if (!(skb = l3_alloc_skb(l)))
2723 memcpy(skb_put(skb, l), tmp, l);
2725 l3_msg(pc->st, DL_DATA | REQUEST, skb);
2729 l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
2731 pc->para.cause = 0x29; /* Temporary failure */
2733 l3dss1_disconnect_req(pc, pr, NULL);
2734 pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
2738 l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg)
2741 pc->para.cause = 0x1b; /* Destination out of order */
2743 pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
2744 release_l3_process(pc);
2748 l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
2750 L3DelTimer(&pc->timer);
2751 L3AddTimer(&pc->timer, T309, CC_T309);
2752 l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
2756 l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
2758 L3DelTimer(&pc->timer);
2760 pc->para.cause = 0x1F; /* normal, unspecified */
2761 l3dss1_status_send(pc, 0, NULL);
2765 static struct stateentry downstatelist[] =
2768 CC_SETUP | REQUEST, l3dss1_setup_req},
2770 CC_RESUME | REQUEST, l3dss1_resume_req},
2771 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
2772 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2774 CC_RELEASE | REQUEST, l3dss1_release_req},
2776 CC_RESTART | REQUEST, l3dss1_restart},
2777 {SBIT(6) | SBIT(25),
2778 CC_IGNORE | REQUEST, l3dss1_reset},
2779 {SBIT(6) | SBIT(25),
2780 CC_REJECT | REQUEST, l3dss1_reject_req},
2781 {SBIT(6) | SBIT(25),
2782 CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
2784 CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
2786 CC_MORE_INFO | REQUEST, l3dss1_dummy},
2787 {SBIT(6) | SBIT(9) | SBIT(25),
2788 CC_ALERTING | REQUEST, l3dss1_alert_req},
2789 {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
2790 CC_SETUP | RESPONSE, l3dss1_setup_rsp},
2792 CC_SUSPEND | REQUEST, l3dss1_suspend_req},
2793 {SBIT(7) | SBIT(9) | SBIT(25),
2794 CC_REDIR | REQUEST, l3dss1_redir_req},
2796 CC_REDIR | REQUEST, l3dss1_redir_req_early},
2797 {SBIT(9) | SBIT(25),
2798 CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
2800 CC_T302, l3dss1_t302},
2802 CC_T303, l3dss1_t303},
2804 CC_T304, l3dss1_t304},
2806 CC_T310, l3dss1_t310},
2808 CC_T313, l3dss1_t313},
2810 CC_T305, l3dss1_t305},
2812 CC_T319, l3dss1_t319},
2814 CC_T318, l3dss1_t318},
2816 CC_T308_1, l3dss1_t308_1},
2818 CC_T308_2, l3dss1_t308_2},
2820 CC_T309, l3dss1_dl_release},
2824 (sizeof(downstatelist) / sizeof(struct stateentry))
2826 static struct stateentry datastatelist[] =
2829 MT_STATUS_ENQUIRY, l3dss1_status_enq},
2831 MT_FACILITY, l3dss1_facility},
2833 MT_STATUS, l3dss1_release_ind},
2835 MT_STATUS, l3dss1_status},
2837 MT_SETUP, l3dss1_setup},
2838 {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
2839 SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2840 MT_SETUP, l3dss1_dummy},
2842 MT_CALL_PROCEEDING, l3dss1_call_proc},
2844 MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
2846 MT_ALERTING, l3dss1_alerting},
2848 MT_PROGRESS, l3dss1_progress},
2849 {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
2850 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2851 MT_INFORMATION, l3dss1_information},
2852 {SBIT(10) | SBIT(11) | SBIT(15),
2853 MT_NOTIFY, l3dss1_notify},
2854 {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
2855 SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
2856 MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
2857 {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),
2858 MT_RELEASE, l3dss1_release},
2859 {SBIT(19), MT_RELEASE, l3dss1_release_ind},
2860 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
2861 MT_DISCONNECT, l3dss1_disconnect},
2863 MT_DISCONNECT, l3dss1_dummy},
2864 {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
2865 MT_CONNECT, l3dss1_connect},
2867 MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
2869 MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
2871 MT_SUSPEND_REJECT, l3dss1_suspend_rej},
2873 MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
2875 MT_RESUME_REJECT, l3dss1_resume_rej},
2879 (sizeof(datastatelist) / sizeof(struct stateentry))
2881 static struct stateentry globalmes_list[] =
2884 MT_STATUS, l3dss1_status},
2886 MT_RESTART, l3dss1_global_restart},
2888 MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
2891 #define GLOBALM_LEN \
2892 (sizeof(globalmes_list) / sizeof(struct stateentry))
2894 static struct stateentry manstatelist[] =
2897 DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
2899 DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
2901 DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
2903 DL_RELEASE | INDICATION, l3dss1_dl_release},
2907 (sizeof(manstatelist) / sizeof(struct stateentry))
2912 global_handler(struct PStack *st, int mt, struct sk_buff *skb)
2918 struct l3_process *proc = st->l3.global;
2920 proc->callref = skb->data[2]; /* cr flag */
2921 for (i = 0; i < GLOBALM_LEN; i++)
2922 if ((mt == globalmes_list[i].primitive) &&
2923 ((1 << proc->state) & globalmes_list[i].state))
2925 if (i == GLOBALM_LEN) {
2926 if (st->l3.debug & L3_DEB_STATE) {
2927 l3_debug(st, "dss1 global state %d mt %x unhandled",
2930 MsgHead(p, proc->callref, MT_STATUS);
2934 *p++ = 81 |0x80; /* invalid cr */
2935 *p++ = 0x14; /* CallState */
2937 *p++ = proc->state & 0x3f;
2939 if (!(skb = l3_alloc_skb(l)))
2941 memcpy(skb_put(skb, l), tmp, l);
2942 l3_msg(proc->st, DL_DATA | REQUEST, skb);
2944 if (st->l3.debug & L3_DEB_STATE) {
2945 l3_debug(st, "dss1 global %d mt %x",
2948 globalmes_list[i].rout(proc, mt, skb);
2953 dss1up(struct PStack *st, int pr, void *arg)
2955 int i, mt, cr, cause, callState;
2958 struct sk_buff *skb = arg;
2959 struct l3_process *proc;
2962 case (DL_DATA | INDICATION):
2963 case (DL_UNIT_DATA | INDICATION):
2965 case (DL_ESTABLISH | CONFIRM):
2966 case (DL_ESTABLISH | INDICATION):
2967 case (DL_RELEASE | INDICATION):
2968 case (DL_RELEASE | CONFIRM):
2969 l3_msg(st, pr, arg);
2973 printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
2977 l3_debug(st, "dss1up frame too short(%d)", skb->len);
2982 if (skb->data[0] != PROTO_DIS_EURO) {
2983 if (st->l3.debug & L3_DEB_PROTERR) {
2984 l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
2985 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
2986 skb->data[0], skb->len);
2991 cr = getcallref(skb->data);
2992 if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
2993 l3_debug(st, "dss1up frame too short(%d)", skb->len);
2997 mt = skb->data[skb->data[1] + 2];
2998 if (st->l3.debug & L3_DEB_STATE)
2999 l3_debug(st, "dss1up cr %d", cr);
3000 if (cr == -2) { /* wrong Callref */
3001 if (st->l3.debug & L3_DEB_WARN)
3002 l3_debug(st, "dss1up wrong Callref");
3005 } else if (cr == -1) { /* Dummy Callref */
3006 if (mt == MT_FACILITY)
3007 if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
3008 l3dss1_parse_facility(st, NULL,
3009 (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
3013 if (st->l3.debug & L3_DEB_WARN)
3014 l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
3017 } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
3018 (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
3019 if (st->l3.debug & L3_DEB_STATE)
3020 l3_debug(st, "dss1up Global CallRef");
3021 global_handler(st, mt, skb);
3024 } else if (!(proc = getl3proc(st, cr))) {
3025 /* No transaction process exist, that means no call with
3026 * this callreference is active
3028 if (mt == MT_SETUP) {
3029 /* Setup creates a new transaction process */
3030 if (skb->data[2] & 0x80) {
3031 /* Setup with wrong CREF flag */
3032 if (st->l3.debug & L3_DEB_STATE)
3033 l3_debug(st, "dss1up wrong CRef flag");
3037 if (!(proc = dss1_new_l3_process(st, cr))) {
3038 /* May be to answer with RELEASE_COMPLETE and
3039 * CAUSE 0x2f "Resource unavailable", but this
3040 * need a new_l3_process too ... arghh
3045 } else if (mt == MT_STATUS) {
3047 if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
3051 cause = *ptr & 0x7f;
3054 if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
3060 /* ETS 300-104 part 2.4.1
3061 * if setup has not been made and a message type
3062 * MT_STATUS is received with call state == 0,
3063 * we must send nothing
3065 if (callState != 0) {
3066 /* ETS 300-104 part 2.4.2
3067 * if setup has not been made and a message type
3068 * MT_STATUS is received with call state != 0,
3069 * we must send MT_RELEASE_COMPLETE cause 101
3071 if ((proc = dss1_new_l3_process(st, cr))) {
3072 proc->para.cause = 101;
3073 l3dss1_msg_without_setup(proc, 0, NULL);
3078 } else if (mt == MT_RELEASE_COMPLETE) {
3082 /* ETS 300-104 part 2
3083 * if setup has not been made and a message type
3084 * (except MT_SETUP and RELEASE_COMPLETE) is received,
3085 * we must send MT_RELEASE_COMPLETE cause 81 */
3087 if ((proc = dss1_new_l3_process(st, cr))) {
3088 proc->para.cause = 81;
3089 l3dss1_msg_without_setup(proc, 0, NULL);
3094 if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
3098 if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
3099 l3dss1_deliver_display(proc, pr, p); /* Display IE included */
3100 for (i = 0; i < DATASLLEN; i++)
3101 if ((mt == datastatelist[i].primitive) &&
3102 ((1 << proc->state) & datastatelist[i].state))
3104 if (i == DATASLLEN) {
3105 if (st->l3.debug & L3_DEB_STATE) {
3106 l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
3107 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3110 if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
3111 proc->para.cause = 101;
3112 l3dss1_status_send(proc, pr, skb);
3115 if (st->l3.debug & L3_DEB_STATE) {
3116 l3_debug(st, "dss1up%sstate %d mt %x",
3117 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
3120 datastatelist[i].rout(proc, pr, skb);
3127 dss1down(struct PStack *st, int pr, void *arg)
3130 struct l3_process *proc;
3131 struct Channel *chan;
3133 if ((DL_ESTABLISH | REQUEST) == pr) {
3134 l3_msg(st, pr, NULL);
3136 } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
3140 if ((proc = dss1_new_l3_process(st, cr))) {
3143 memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
3150 printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
3154 if ( pr == (CC_TDSS1_IO | REQUEST)) {
3155 l3dss1_io_timer(proc); /* timer expires */
3159 for (i = 0; i < DOWNSLLEN; i++)
3160 if ((pr == downstatelist[i].primitive) &&
3161 ((1 << proc->state) & downstatelist[i].state))
3163 if (i == DOWNSLLEN) {
3164 if (st->l3.debug & L3_DEB_STATE) {
3165 l3_debug(st, "dss1down state %d prim %#x unhandled",
3169 if (st->l3.debug & L3_DEB_STATE) {
3170 l3_debug(st, "dss1down state %d prim %#x",
3173 downstatelist[i].rout(proc, pr, arg);
3178 dss1man(struct PStack *st, int pr, void *arg)
3181 struct l3_process *proc = arg;
3184 printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
3187 for (i = 0; i < MANSLLEN; i++)
3188 if ((pr == manstatelist[i].primitive) &&
3189 ((1 << proc->state) & manstatelist[i].state))
3191 if (i == MANSLLEN) {
3192 if (st->l3.debug & L3_DEB_STATE) {
3193 l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
3194 proc->callref & 0x7f, proc->state, pr);
3197 if (st->l3.debug & L3_DEB_STATE) {
3198 l3_debug(st, "cr %d dss1man state %d prim %#x",
3199 proc->callref & 0x7f, proc->state, pr);
3201 manstatelist[i].rout(proc, pr, arg);
3206 setstack_dss1(struct PStack *st)
3211 st->lli.l4l3 = dss1down;
3212 st->lli.l4l3_proto = l3dss1_cmd_global;
3213 st->l2.l2l3 = dss1up;
3214 st->l3.l3ml3 = dss1man;
3216 st->prot.dss1.last_invoke_id = 0;
3217 st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
3220 st->prot.dss1.invoke_used[i++] = 0;
3222 if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
3223 printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
3225 st->l3.global->state = 0;
3226 st->l3.global->callref = 0;
3227 st->l3.global->next = NULL;
3228 st->l3.global->debug = L3_DEB_WARN;
3229 st->l3.global->st = st;
3230 st->l3.global->N303 = 1;
3231 st->l3.global->prot.dss1.invoke_id = 0;
3233 L3InitTimer(st->l3.global, &st->l3.global->timer);
3235 strcpy(tmp, dss1_revision);
3236 printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));