| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* $Id: l3dss1.c,v 2.32.2.3 2004/01/13 14:31:25 keil Exp $ |
| 2 | * |
| 3 | * EURO/DSS1 D-channel protocol |
| 4 | * |
| 5 | * German 1TR6 D-channel protocol |
| 6 | * |
| 7 | * Author Karsten Keil |
| 8 | * based on the teles driver from Jan den Ouden |
| 9 | * Copyright by Karsten Keil <keil@isdn4linux.de> |
| 10 | * |
| 11 | * This software may be used and distributed according to the terms |
| 12 | * of the GNU General Public License, incorporated herein by reference. |
| 13 | * |
| 14 | * For changes and modifications please read |
| 15 | * Documentation/isdn/HiSax.cert |
| 16 | * |
| 17 | * Thanks to Jan den Ouden |
| 18 | * Fritz Elfert |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "hisax.h" |
| 23 | #include "isdnl3.h" |
| 24 | #include "l3dss1.h" |
| 25 | #include <linux/ctype.h> |
| 26 | #include <linux/slab.h> |
| 27 | |
| 28 | extern char *HiSax_getrev(const char *revision); |
| 29 | static const char *dss1_revision = "$Revision: 2.32.2.3 $"; |
| 30 | |
| 31 | #define EXT_BEARER_CAPS 1 |
| 32 | |
| 33 | #define MsgHead(ptr, cref, mty) \ |
| 34 | *ptr++ = 0x8; \ |
| 35 | if (cref == -1) { \ |
| 36 | *ptr++ = 0x0; \ |
| 37 | } else { \ |
| 38 | *ptr++ = 0x1; \ |
| 39 | *ptr++ = cref^0x80; \ |
| 40 | } \ |
| 41 | *ptr++ = mty |
| 42 | |
| 43 | |
| 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) |
| 49 | { |
| 50 | unsigned char retval; |
| 51 | int i; |
| 52 | |
| 53 | i = 32; /* maximum search depth */ |
| 54 | |
| 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; |
| 58 | i--; |
| 59 | } |
| 60 | if (i) { |
| 61 | while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7))) |
| 62 | retval++; |
| 63 | } else |
| 64 | retval = 0; |
| 65 | p->prot.dss1.last_invoke_id = retval; |
| 66 | p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7)); |
| 67 | return (retval); |
| 68 | } /* new_invoke_id */ |
| 69 | |
| 70 | /*************************/ |
| 71 | /* free a used invoke id */ |
| 72 | /*************************/ |
| 73 | static void free_invoke_id(struct PStack *p, unsigned char id) |
| 74 | { |
| 75 | |
| 76 | if (!id) return; /* 0 = invalid value */ |
| 77 | |
| 78 | p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7)); |
| 79 | } /* free_invoke_id */ |
| 80 | |
| 81 | |
| 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; |
| 88 | |
| 89 | if (!(proc = new_l3_process(st, cr))) |
| 90 | return (NULL); |
| 91 | |
| 92 | proc->prot.dss1.invoke_id = 0; |
| 93 | proc->prot.dss1.remote_operation = 0; |
| 94 | proc->prot.dss1.uus1_data[0] = '\0'; |
| 95 | |
| 96 | return (proc); |
| 97 | } /* dss1_new_l3_process */ |
| 98 | |
| 99 | /************************************************/ |
| 100 | /* free a l3 process and all dss1 specific data */ |
| 101 | /************************************************/ |
| 102 | static void |
| 103 | dss1_release_l3_process(struct l3_process *p) |
| 104 | { |
| 105 | free_invoke_id(p->st, p->prot.dss1.invoke_id); |
| 106 | release_l3_process(p); |
| 107 | } /* dss1_release_l3_process */ |
| 108 | |
| 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 */ |
| 115 | |
| 116 | if (!id) return (NULL); |
| 117 | |
| 118 | while (pc) |
| 119 | { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id)) |
| 120 | return (pc); |
| 121 | pc = pc->next; |
| 122 | } |
| 123 | return (NULL); |
| 124 | } /* l3dss1_search_dummy_proc */ |
| 125 | |
| 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 | /*******************************************************************/ |
| 130 | static void |
| 131 | l3dss1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen) |
| 132 | { isdn_ctrl ic; |
| 133 | struct IsdnCardState *cs; |
| 134 | struct l3_process *pc = NULL; |
| 135 | |
| 136 | if ((pc = l3dss1_search_dummy_proc(st, id))) |
| 137 | { L3DelTimer(&pc->timer); /* remove timer */ |
| 138 | |
| 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 */ |
| 151 | |
| 152 | cs->iif.statcallb(&ic); |
| 153 | dss1_release_l3_process(pc); |
| 154 | } |
| 155 | else |
| 156 | l3_debug(st, "dummy return result id=0x%x result len=%d", id, nlen); |
| 157 | } /* l3dss1_dummy_return_result */ |
| 158 | |
| 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 | /*******************************************************************/ |
| 163 | static void |
| 164 | l3dss1_dummy_error_return(struct PStack *st, int id, ulong error) |
| 165 | { isdn_ctrl ic; |
| 166 | struct IsdnCardState *cs; |
| 167 | struct l3_process *pc = NULL; |
| 168 | |
| 169 | if ((pc = l3dss1_search_dummy_proc(st, id))) |
| 170 | { L3DelTimer(&pc->timer); /* remove timer */ |
| 171 | |
| 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 */ |
| 184 | |
| 185 | cs->iif.statcallb(&ic); |
| 186 | dss1_release_l3_process(pc); |
| 187 | } |
| 188 | else |
| 189 | l3_debug(st, "dummy return error id=0x%x error=0x%lx", id, error); |
| 190 | } /* l3dss1_error_return */ |
| 191 | |
| 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 | /*******************************************************************/ |
| 196 | static void |
| 197 | l3dss1_dummy_invoke(struct PStack *st, int cr, int id, |
| 198 | int ident, u_char *p, u_char nlen) |
| 199 | { isdn_ctrl ic; |
| 200 | struct IsdnCardState *cs; |
| 201 | |
| 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 */ |
| 205 | |
| 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; |
| 216 | |
| 217 | cs->iif.statcallb(&ic); |
| 218 | } /* l3dss1_dummy_invoke */ |
| 219 | |
| 220 | static void |
| 221 | l3dss1_parse_facility(struct PStack *st, struct l3_process *pc, |
| 222 | int cr, u_char *p) |
| 223 | { |
| 224 | int qd_len = 0; |
| 225 | unsigned char nlen = 0, ilen, cp_tag; |
| 226 | int ident, id; |
| 227 | ulong err_ret; |
| 228 | |
| 229 | if (pc) |
| 230 | st = pc->st; /* valid Stack */ |
| 231 | else |
| 232 | if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */ |
| 233 | |
| 234 | p++; |
| 235 | qd_len = *p++; |
| 236 | if (qd_len == 0) { |
| 237 | l3_debug(st, "qd_len == 0"); |
| 238 | return; |
| 239 | } |
| 240 | if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */ |
| 241 | l3_debug(st, "supplementary service != 0x11"); |
| 242 | return; |
| 243 | } |
| 244 | while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */ |
| 245 | p++; |
| 246 | qd_len--; |
| 247 | } |
| 248 | if (qd_len < 2) { |
| 249 | l3_debug(st, "qd_len < 2"); |
| 250 | return; |
| 251 | } |
| 252 | p++; |
| 253 | qd_len--; |
| 254 | if ((*p & 0xE0) != 0xA0) { /* class and form */ |
| 255 | l3_debug(st, "class and form != 0xA0"); |
| 256 | return; |
| 257 | } |
| 258 | |
| 259 | cp_tag = *p & 0x1F; /* remember tag value */ |
| 260 | |
| 261 | p++; |
| 262 | qd_len--; |
| 263 | if (qd_len < 1) |
| 264 | { l3_debug(st, "qd_len < 1"); |
| 265 | return; |
| 266 | } |
| 267 | if (*p & 0x80) |
| 268 | { /* length format indefinite or limited */ |
| 269 | nlen = *p++ & 0x7F; /* number of len bytes or indefinite */ |
| 270 | if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) || |
| 271 | (nlen > 1)) |
| 272 | { l3_debug(st, "length format error or not implemented"); |
| 273 | return; |
| 274 | } |
| 275 | if (nlen == 1) |
| 276 | { nlen = *p++; /* complete length */ |
| 277 | qd_len--; |
| 278 | } |
| 279 | else |
| 280 | { qd_len -= 2; /* trailing null bytes */ |
| 281 | if ((*(p + qd_len)) || (*(p + qd_len + 1))) |
| 282 | { l3_debug(st, "length format indefinite error"); |
| 283 | return; |
| 284 | } |
| 285 | nlen = qd_len; |
| 286 | } |
| 287 | } |
| 288 | else |
| 289 | { nlen = *p++; |
| 290 | qd_len--; |
| 291 | } |
| 292 | if (qd_len < nlen) |
| 293 | { l3_debug(st, "qd_len < nlen"); |
| 294 | return; |
| 295 | } |
| 296 | qd_len -= nlen; |
| 297 | |
| 298 | if (nlen < 2) |
| 299 | { l3_debug(st, "nlen < 2"); |
| 300 | return; |
| 301 | } |
| 302 | if (*p != 0x02) |
| 303 | { /* invoke identifier tag */ |
| 304 | l3_debug(st, "invoke identifier tag !=0x02"); |
| 305 | return; |
| 306 | } |
| 307 | p++; |
| 308 | nlen--; |
| 309 | if (*p & 0x80) |
| 310 | { /* length format */ |
| 311 | l3_debug(st, "invoke id length format 2"); |
| 312 | return; |
| 313 | } |
| 314 | ilen = *p++; |
| 315 | nlen--; |
| 316 | if (ilen > nlen || ilen == 0) |
| 317 | { l3_debug(st, "ilen > nlen || ilen == 0"); |
| 318 | return; |
| 319 | } |
| 320 | nlen -= ilen; |
| 321 | id = 0; |
| 322 | while (ilen > 0) |
| 323 | { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */ |
| 324 | ilen--; |
| 325 | } |
| 326 | |
| 327 | switch (cp_tag) { /* component tag */ |
| 328 | case 1: /* invoke */ |
| 329 | if (nlen < 2) { |
| 330 | l3_debug(st, "nlen < 2 22"); |
| 331 | return; |
| 332 | } |
| 333 | if (*p != 0x02) { /* operation value */ |
| 334 | l3_debug(st, "operation value !=0x02"); |
| 335 | return; |
| 336 | } |
| 337 | p++; |
| 338 | nlen--; |
| 339 | ilen = *p++; |
| 340 | nlen--; |
| 341 | if (ilen > nlen || ilen == 0) { |
| 342 | l3_debug(st, "ilen > nlen || ilen == 0 22"); |
| 343 | return; |
| 344 | } |
| 345 | nlen -= ilen; |
| 346 | ident = 0; |
| 347 | while (ilen > 0) { |
| 348 | ident = (ident << 8) | (*p++ & 0xFF); |
| 349 | ilen--; |
| 350 | } |
| 351 | |
| 352 | if (!pc) |
| 353 | { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen); |
| 354 | return; |
| 355 | } |
| 356 | #ifdef CONFIG_DE_AOC |
| 357 | { |
| 358 | |
| 359 | #define FOO1(s, a, b) \ |
| 360 | while (nlen > 1) { \ |
| 361 | int ilen = p[1]; \ |
| 362 | if (nlen < ilen + 2) { \ |
| 363 | l3_debug(st, "FOO1 nlen < ilen+2"); \ |
| 364 | return; \ |
| 365 | } \ |
| 366 | nlen -= ilen + 2; \ |
| 367 | if ((*p & 0xFF) == (a)) { \ |
| 368 | int nlen = ilen; \ |
| 369 | p += 2; \ |
| 370 | b; \ |
| 371 | } else { \ |
| 372 | p += ilen + 2; \ |
| 373 | } \ |
| 374 | } |
| 375 | |
| 376 | switch (ident) { |
| 377 | case 0x22: /* during */ |
| 378 | FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( { |
| 379 | ident = 0; |
| 380 | nlen = (nlen) ? nlen : 0; /* Make gcc happy */ |
| 381 | while (ilen > 0) { |
| 382 | ident = (ident << 8) | *p++; |
| 383 | ilen--; |
| 384 | } |
| 385 | if (ident > pc->para.chargeinfo) { |
| 386 | pc->para.chargeinfo = ident; |
| 387 | st->l3.l3l4(st, CC_CHARGE | INDICATION, pc); |
| 388 | } |
| 389 | if (st->l3.debug & L3_DEB_CHARGE) { |
| 390 | if (*(p + 2) == 0) { |
| 391 | l3_debug(st, "charging info during %d", pc->para.chargeinfo); |
| 392 | } |
| 393 | else { |
| 394 | l3_debug(st, "charging info final %d", pc->para.chargeinfo); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | ))))) |
| 399 | break; |
| 400 | case 0x24: /* final */ |
| 401 | FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( { |
| 402 | ident = 0; |
| 403 | nlen = (nlen) ? nlen : 0; /* Make gcc happy */ |
| 404 | while (ilen > 0) { |
| 405 | ident = (ident << 8) | *p++; |
| 406 | ilen--; |
| 407 | } |
| 408 | if (ident > pc->para.chargeinfo) { |
| 409 | pc->para.chargeinfo = ident; |
| 410 | st->l3.l3l4(st, CC_CHARGE | INDICATION, pc); |
| 411 | } |
| 412 | if (st->l3.debug & L3_DEB_CHARGE) { |
| 413 | l3_debug(st, "charging info final %d", pc->para.chargeinfo); |
| 414 | } |
| 415 | } |
| 416 | )))))) |
| 417 | break; |
| 418 | default: |
| 419 | l3_debug(st, "invoke break invalid ident %02x", ident); |
| 420 | break; |
| 421 | } |
| 422 | #undef FOO1 |
| 423 | |
| 424 | } |
| 425 | #else /* not CONFIG_DE_AOC */ |
| 426 | l3_debug(st, "invoke break"); |
| 427 | #endif /* not CONFIG_DE_AOC */ |
| 428 | break; |
| 429 | case 2: /* return result */ |
| 430 | /* if no process available handle separately */ |
| 431 | if (!pc) |
| 432 | { if (cr == -1) |
| 433 | l3dss1_dummy_return_result(st, id, p, nlen); |
| 434 | return; |
| 435 | } |
| 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 */ |
| 443 | else |
| 444 | l3_debug(st, "return error unknown identifier"); |
| 445 | break; |
| 446 | case 3: /* return error */ |
| 447 | err_ret = 0; |
| 448 | if (nlen < 2) |
| 449 | { l3_debug(st, "return error nlen < 2"); |
| 450 | return; |
| 451 | } |
| 452 | if (*p != 0x02) |
| 453 | { /* result tag */ |
| 454 | l3_debug(st, "invoke error tag !=0x02"); |
| 455 | return; |
| 456 | } |
| 457 | p++; |
| 458 | nlen--; |
| 459 | if (*p > 4) |
| 460 | { /* length format */ |
| 461 | l3_debug(st, "invoke return errlen > 4 "); |
| 462 | return; |
| 463 | } |
| 464 | ilen = *p++; |
| 465 | nlen--; |
| 466 | if (ilen > nlen || ilen == 0) |
| 467 | { l3_debug(st, "error return ilen > nlen || ilen == 0"); |
| 468 | return; |
| 469 | } |
| 470 | nlen -= ilen; |
| 471 | while (ilen > 0) |
| 472 | { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */ |
| 473 | ilen--; |
| 474 | } |
| 475 | /* if no process available handle separately */ |
| 476 | if (!pc) |
| 477 | { if (cr == -1) |
| 478 | l3dss1_dummy_error_return(st, id, err_ret); |
| 479 | return; |
| 480 | } |
| 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 */ |
| 489 | else |
| 490 | l3_debug(st, "return result unknown identifier"); |
| 491 | break; |
| 492 | default: |
| 493 | l3_debug(st, "facility default break tag=0x%02x", cp_tag); |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | static void |
| 499 | l3dss1_message(struct l3_process *pc, u_char mt) |
| 500 | { |
| 501 | struct sk_buff *skb; |
| 502 | u_char *p; |
| 503 | |
| 504 | if (!(skb = l3_alloc_skb(4))) |
| 505 | return; |
| 506 | p = skb_put(skb, 4); |
| 507 | MsgHead(p, pc->callref, mt); |
| 508 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | l3dss1_message_cause(struct l3_process *pc, u_char mt, u_char cause) |
| 513 | { |
| 514 | struct sk_buff *skb; |
| 515 | u_char tmp[16]; |
| 516 | u_char *p = tmp; |
| 517 | int l; |
| 518 | |
| 519 | MsgHead(p, pc->callref, mt); |
| 520 | *p++ = IE_CAUSE; |
| 521 | *p++ = 0x2; |
| 522 | *p++ = 0x80; |
| 523 | *p++ = cause | 0x80; |
| 524 | |
| 525 | l = p - tmp; |
| 526 | if (!(skb = l3_alloc_skb(l))) |
| 527 | return; |
| 528 | skb_put_data(skb, tmp, l); |
| 529 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 530 | } |
| 531 | |
| 532 | static void |
| 533 | l3dss1_status_send(struct l3_process *pc, u_char pr, void *arg) |
| 534 | { |
| 535 | u_char tmp[16]; |
| 536 | u_char *p = tmp; |
| 537 | int l; |
| 538 | struct sk_buff *skb; |
| 539 | |
| 540 | MsgHead(p, pc->callref, MT_STATUS); |
| 541 | |
| 542 | *p++ = IE_CAUSE; |
| 543 | *p++ = 0x2; |
| 544 | *p++ = 0x80; |
| 545 | *p++ = pc->para.cause | 0x80; |
| 546 | |
| 547 | *p++ = IE_CALL_STATE; |
| 548 | *p++ = 0x1; |
| 549 | *p++ = pc->state & 0x3f; |
| 550 | |
| 551 | l = p - tmp; |
| 552 | if (!(skb = l3_alloc_skb(l))) |
| 553 | return; |
| 554 | skb_put_data(skb, tmp, l); |
| 555 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 556 | } |
| 557 | |
| 558 | static void |
| 559 | l3dss1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg) |
| 560 | { |
| 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 |
| 564 | */ |
| 565 | u_char tmp[16]; |
| 566 | u_char *p = tmp; |
| 567 | int l; |
| 568 | struct sk_buff *skb; |
| 569 | |
| 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); |
| 577 | *p++ = IE_CAUSE; |
| 578 | *p++ = 0x2; |
| 579 | *p++ = 0x80; |
| 580 | *p++ = pc->para.cause | 0x80; |
| 581 | break; |
| 582 | default: |
| 583 | printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n", |
| 584 | pc->para.cause); |
| 585 | return; |
| 586 | } |
| 587 | l = p - tmp; |
| 588 | if (!(skb = l3_alloc_skb(l))) |
| 589 | return; |
| 590 | skb_put_data(skb, tmp, l); |
| 591 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 592 | dss1_release_l3_process(pc); |
| 593 | } |
| 594 | |
| 595 | static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1, |
| 596 | IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC, |
| 597 | IE_USER_USER, -1}; |
| 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, |
| 607 | IE_CALLED_PN, -1}; |
| 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}; |
| 615 | */ |
| 616 | static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY, |
| 617 | IE_DISPLAY, -1}; |
| 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}; |
| 631 | /* not used |
| 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 | |
| 636 | * IE_MANDATORY, -1}; |
| 637 | */ |
| 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}; |
| 641 | |
| 642 | struct ie_len { |
| 643 | int ie; |
| 644 | int len; |
| 645 | }; |
| 646 | |
| 647 | static |
| 648 | struct ie_len max_ie_len[] = { |
| 649 | {IE_SEGMENT, 4}, |
| 650 | {IE_BEARER, 12}, |
| 651 | {IE_CAUSE, 32}, |
| 652 | {IE_CALL_ID, 10}, |
| 653 | {IE_CALL_STATE, 3}, |
| 654 | {IE_CHANNEL_ID, 34}, |
| 655 | {IE_FACILITY, 255}, |
| 656 | {IE_PROGRESS, 4}, |
| 657 | {IE_NET_FAC, 255}, |
| 658 | {IE_NOTIFY, 3}, |
| 659 | {IE_DISPLAY, 82}, |
| 660 | {IE_DATE, 8}, |
| 661 | {IE_KEYPAD, 34}, |
| 662 | {IE_SIGNAL, 3}, |
| 663 | {IE_INFORATE, 6}, |
| 664 | {IE_E2E_TDELAY, 11}, |
| 665 | {IE_TDELAY_SEL, 5}, |
| 666 | {IE_PACK_BINPARA, 3}, |
| 667 | {IE_PACK_WINSIZE, 4}, |
| 668 | {IE_PACK_SIZE, 4}, |
| 669 | {IE_CUG, 7}, |
| 670 | {IE_REV_CHARGE, 3}, |
| 671 | {IE_CALLING_PN, 24}, |
| 672 | {IE_CALLING_SUB, 23}, |
| 673 | {IE_CALLED_PN, 24}, |
| 674 | {IE_CALLED_SUB, 23}, |
| 675 | {IE_REDIR_NR, 255}, |
| 676 | {IE_TRANS_SEL, 255}, |
| 677 | {IE_RESTART_IND, 3}, |
| 678 | {IE_LLC, 18}, |
| 679 | {IE_HLC, 5}, |
| 680 | {IE_USER_USER, 131}, |
| 681 | {-1, 0}, |
| 682 | }; |
| 683 | |
| 684 | static int |
| 685 | getmax_ie_len(u_char ie) { |
| 686 | int i = 0; |
| 687 | while (max_ie_len[i].ie != -1) { |
| 688 | if (max_ie_len[i].ie == ie) |
| 689 | return (max_ie_len[i].len); |
| 690 | i++; |
| 691 | } |
| 692 | return (255); |
| 693 | } |
| 694 | |
| 695 | static int |
| 696 | ie_in_set(struct l3_process *pc, u_char ie, int *checklist) { |
| 697 | int ret = 1; |
| 698 | |
| 699 | while (*checklist != -1) { |
| 700 | if ((*checklist & 0xff) == ie) { |
| 701 | if (ie & 0x80) |
| 702 | return (-ret); |
| 703 | else |
| 704 | return (ret); |
| 705 | } |
| 706 | ret++; |
| 707 | checklist++; |
| 708 | } |
| 709 | return (0); |
| 710 | } |
| 711 | |
| 712 | static int |
| 713 | check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist) |
| 714 | { |
| 715 | int *cl = checklist; |
| 716 | u_char mt; |
| 717 | u_char *p, ie; |
| 718 | int l, newpos, oldpos; |
| 719 | int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0; |
| 720 | u_char codeset = 0; |
| 721 | u_char old_codeset = 0; |
| 722 | u_char codelock = 1; |
| 723 | |
| 724 | p = skb->data; |
| 725 | /* skip cr */ |
| 726 | p++; |
| 727 | l = (*p++) & 0xf; |
| 728 | p += l; |
| 729 | mt = *p++; |
| 730 | oldpos = 0; |
| 731 | while ((p - skb->data) < skb->len) { |
| 732 | if ((*p & 0xf0) == 0x90) { /* shift codeset */ |
| 733 | old_codeset = codeset; |
| 734 | codeset = *p & 7; |
| 735 | if (*p & 0x08) |
| 736 | codelock = 0; |
| 737 | else |
| 738 | codelock = 1; |
| 739 | if (pc->debug & L3_DEB_CHECK) |
| 740 | l3_debug(pc->st, "check IE shift%scodeset %d->%d", |
| 741 | codelock ? " locking " : " ", old_codeset, codeset); |
| 742 | p++; |
| 743 | continue; |
| 744 | } |
| 745 | if (!codeset) { /* only codeset 0 */ |
| 746 | if ((newpos = ie_in_set(pc, *p, cl))) { |
| 747 | if (newpos > 0) { |
| 748 | if (newpos < oldpos) |
| 749 | err_seq++; |
| 750 | else |
| 751 | oldpos = newpos; |
| 752 | } |
| 753 | } else { |
| 754 | if (ie_in_set(pc, *p, comp_required)) |
| 755 | err_compr++; |
| 756 | else |
| 757 | err_ureg++; |
| 758 | } |
| 759 | } |
| 760 | ie = *p++; |
| 761 | if (ie & 0x80) { |
| 762 | l = 1; |
| 763 | } else { |
| 764 | l = *p++; |
| 765 | p += l; |
| 766 | l += 2; |
| 767 | } |
| 768 | if (!codeset && (l > getmax_ie_len(ie))) |
| 769 | err_len++; |
| 770 | if (!codelock) { |
| 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; |
| 775 | codelock = 1; |
| 776 | } |
| 777 | } |
| 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); |
| 782 | if (err_compr) |
| 783 | return (ERR_IE_COMPREHENSION); |
| 784 | if (err_ureg) |
| 785 | return (ERR_IE_UNRECOGNIZED); |
| 786 | if (err_len) |
| 787 | return (ERR_IE_LENGTH); |
| 788 | if (err_seq) |
| 789 | return (ERR_IE_SEQUENCE); |
| 790 | } |
| 791 | return (0); |
| 792 | } |
| 793 | |
| 794 | /* verify if a message type exists and contain no IE error */ |
| 795 | static int |
| 796 | l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg) |
| 797 | { |
| 798 | switch (mt) { |
| 799 | case MT_ALERTING: |
| 800 | case MT_CALL_PROCEEDING: |
| 801 | case MT_CONNECT: |
| 802 | case MT_CONNECT_ACKNOWLEDGE: |
| 803 | case MT_DISCONNECT: |
| 804 | case MT_INFORMATION: |
| 805 | case MT_FACILITY: |
| 806 | case MT_NOTIFY: |
| 807 | case MT_PROGRESS: |
| 808 | case MT_RELEASE: |
| 809 | case MT_RELEASE_COMPLETE: |
| 810 | case MT_SETUP: |
| 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: |
| 817 | case MT_RESTART: |
| 818 | case MT_RESTART_ACKNOWLEDGE: |
| 819 | case MT_CONGESTION_CONTROL: |
| 820 | case MT_STATUS: |
| 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); |
| 824 | break; |
| 825 | case MT_RESUME: /* RESUME only in user->net */ |
| 826 | case MT_SUSPEND: /* SUSPEND only in user->net */ |
| 827 | default: |
| 828 | if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN)) |
| 829 | l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt); |
| 830 | pc->para.cause = 97; |
| 831 | l3dss1_status_send(pc, 0, NULL); |
| 832 | return (1); |
| 833 | } |
| 834 | return (0); |
| 835 | } |
| 836 | |
| 837 | static void |
| 838 | l3dss1_std_ie_err(struct l3_process *pc, int ret) { |
| 839 | |
| 840 | if (pc->debug & L3_DEB_CHECK) |
| 841 | l3_debug(pc->st, "check_infoelements ret %d", ret); |
| 842 | switch (ret) { |
| 843 | case 0: |
| 844 | break; |
| 845 | case ERR_IE_COMPREHENSION: |
| 846 | pc->para.cause = 96; |
| 847 | l3dss1_status_send(pc, 0, NULL); |
| 848 | break; |
| 849 | case ERR_IE_UNRECOGNIZED: |
| 850 | pc->para.cause = 99; |
| 851 | l3dss1_status_send(pc, 0, NULL); |
| 852 | break; |
| 853 | case ERR_IE_LENGTH: |
| 854 | pc->para.cause = 100; |
| 855 | l3dss1_status_send(pc, 0, NULL); |
| 856 | break; |
| 857 | case ERR_IE_SEQUENCE: |
| 858 | default: |
| 859 | break; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | static int |
| 864 | l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) { |
| 865 | u_char *p; |
| 866 | |
| 867 | p = skb->data; |
| 868 | if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) { |
| 869 | p++; |
| 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); |
| 873 | return (-2); |
| 874 | } |
| 875 | 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); |
| 879 | return (-3); |
| 880 | } |
| 881 | return (*p & 0x3); |
| 882 | } else |
| 883 | return (-1); |
| 884 | } |
| 885 | |
| 886 | static int |
| 887 | l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) { |
| 888 | u_char l, i = 0; |
| 889 | u_char *p; |
| 890 | |
| 891 | p = skb->data; |
| 892 | pc->para.cause = 31; |
| 893 | pc->para.loc = 0; |
| 894 | if ((p = findie(p, skb->len, IE_CAUSE, 0))) { |
| 895 | p++; |
| 896 | l = *p++; |
| 897 | if (l > 30) |
| 898 | return (1); |
| 899 | if (l) { |
| 900 | pc->para.loc = *p++; |
| 901 | l--; |
| 902 | } else { |
| 903 | return (2); |
| 904 | } |
| 905 | if (l && !(pc->para.loc & 0x80)) { |
| 906 | l--; |
| 907 | p++; /* skip recommendation */ |
| 908 | } |
| 909 | if (l) { |
| 910 | pc->para.cause = *p++; |
| 911 | l--; |
| 912 | if (!(pc->para.cause & 0x80)) |
| 913 | return (3); |
| 914 | } else |
| 915 | return (4); |
| 916 | while (l && (i < 6)) { |
| 917 | pc->para.diag[i++] = *p++; |
| 918 | l--; |
| 919 | } |
| 920 | } else |
| 921 | return (-1); |
| 922 | return (0); |
| 923 | } |
| 924 | |
| 925 | static void |
| 926 | l3dss1_msg_with_uus(struct l3_process *pc, u_char cmd) |
| 927 | { |
| 928 | struct sk_buff *skb; |
| 929 | u_char tmp[16 + 40]; |
| 930 | u_char *p = tmp; |
| 931 | int l; |
| 932 | |
| 933 | MsgHead(p, pc->callref, cmd); |
| 934 | |
| 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'; |
| 942 | } |
| 943 | |
| 944 | l = p - tmp; |
| 945 | if (!(skb = l3_alloc_skb(l))) |
| 946 | return; |
| 947 | skb_put_data(skb, tmp, l); |
| 948 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 949 | } /* l3dss1_msg_with_uus */ |
| 950 | |
| 951 | static void |
| 952 | l3dss1_release_req(struct l3_process *pc, u_char pr, void *arg) |
| 953 | { |
| 954 | StopAllL3Timer(pc); |
| 955 | newl3state(pc, 19); |
| 956 | if (!pc->prot.dss1.uus1_data[0]) |
| 957 | l3dss1_message(pc, MT_RELEASE); |
| 958 | else |
| 959 | l3dss1_msg_with_uus(pc, MT_RELEASE); |
| 960 | L3AddTimer(&pc->timer, T308, CC_T308_1); |
| 961 | } |
| 962 | |
| 963 | static void |
| 964 | l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg) |
| 965 | { |
| 966 | struct sk_buff *skb = arg; |
| 967 | int ret; |
| 968 | |
| 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); |
| 972 | } else if (ret < 0) |
| 973 | pc->para.cause = NO_CAUSE; |
| 974 | StopAllL3Timer(pc); |
| 975 | newl3state(pc, 0); |
| 976 | pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc); |
| 977 | dss1_release_l3_process(pc); |
| 978 | } |
| 979 | |
| 980 | #ifdef EXT_BEARER_CAPS |
| 981 | |
| 982 | static u_char * |
| 983 | EncodeASyncParams(u_char *p, u_char si2) |
| 984 | { // 7c 06 88 90 21 42 00 bb |
| 985 | |
| 986 | p[0] = 0; |
| 987 | p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19 |
| 988 | p[2] = 0x80; |
| 989 | if (si2 & 32) // 7 data bits |
| 990 | |
| 991 | p[2] += 16; |
| 992 | else // 8 data bits |
| 993 | |
| 994 | p[2] += 24; |
| 995 | |
| 996 | if (si2 & 16) // 2 stop bits |
| 997 | |
| 998 | p[2] += 96; |
| 999 | else // 1 stop bit |
| 1000 | |
| 1001 | p[2] += 32; |
| 1002 | |
| 1003 | if (si2 & 8) // even parity |
| 1004 | |
| 1005 | p[2] += 2; |
| 1006 | else // no parity |
| 1007 | |
| 1008 | p[2] += 3; |
| 1009 | |
| 1010 | switch (si2 & 0x07) { |
| 1011 | case 0: |
| 1012 | p[0] = 66; // 1200 bit/s |
| 1013 | |
| 1014 | break; |
| 1015 | case 1: |
| 1016 | p[0] = 88; // 1200/75 bit/s |
| 1017 | |
| 1018 | break; |
| 1019 | case 2: |
| 1020 | p[0] = 87; // 75/1200 bit/s |
| 1021 | |
| 1022 | break; |
| 1023 | case 3: |
| 1024 | p[0] = 67; // 2400 bit/s |
| 1025 | |
| 1026 | break; |
| 1027 | case 4: |
| 1028 | p[0] = 69; // 4800 bit/s |
| 1029 | |
| 1030 | break; |
| 1031 | case 5: |
| 1032 | p[0] = 72; // 9600 bit/s |
| 1033 | |
| 1034 | break; |
| 1035 | case 6: |
| 1036 | p[0] = 73; // 14400 bit/s |
| 1037 | |
| 1038 | break; |
| 1039 | case 7: |
| 1040 | p[0] = 75; // 19200 bit/s |
| 1041 | |
| 1042 | break; |
| 1043 | } |
| 1044 | return p + 3; |
| 1045 | } |
| 1046 | |
| 1047 | static u_char |
| 1048 | EncodeSyncParams(u_char si2, u_char ai) |
| 1049 | { |
| 1050 | |
| 1051 | switch (si2) { |
| 1052 | case 0: |
| 1053 | return ai + 2; // 1200 bit/s |
| 1054 | |
| 1055 | case 1: |
| 1056 | return ai + 24; // 1200/75 bit/s |
| 1057 | |
| 1058 | case 2: |
| 1059 | return ai + 23; // 75/1200 bit/s |
| 1060 | |
| 1061 | case 3: |
| 1062 | return ai + 3; // 2400 bit/s |
| 1063 | |
| 1064 | case 4: |
| 1065 | return ai + 5; // 4800 bit/s |
| 1066 | |
| 1067 | case 5: |
| 1068 | return ai + 8; // 9600 bit/s |
| 1069 | |
| 1070 | case 6: |
| 1071 | return ai + 9; // 14400 bit/s |
| 1072 | |
| 1073 | case 7: |
| 1074 | return ai + 11; // 19200 bit/s |
| 1075 | |
| 1076 | case 8: |
| 1077 | return ai + 14; // 48000 bit/s |
| 1078 | |
| 1079 | case 9: |
| 1080 | return ai + 15; // 56000 bit/s |
| 1081 | |
| 1082 | case 15: |
| 1083 | return ai + 40; // negotiate bit/s |
| 1084 | |
| 1085 | default: |
| 1086 | break; |
| 1087 | } |
| 1088 | return ai; |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | static u_char |
| 1093 | DecodeASyncParams(u_char si2, u_char *p) |
| 1094 | { |
| 1095 | u_char info; |
| 1096 | |
| 1097 | switch (p[5]) { |
| 1098 | case 66: // 1200 bit/s |
| 1099 | |
| 1100 | break; // si2 don't change |
| 1101 | |
| 1102 | case 88: // 1200/75 bit/s |
| 1103 | |
| 1104 | si2 += 1; |
| 1105 | break; |
| 1106 | case 87: // 75/1200 bit/s |
| 1107 | |
| 1108 | si2 += 2; |
| 1109 | break; |
| 1110 | case 67: // 2400 bit/s |
| 1111 | |
| 1112 | si2 += 3; |
| 1113 | break; |
| 1114 | case 69: // 4800 bit/s |
| 1115 | |
| 1116 | si2 += 4; |
| 1117 | break; |
| 1118 | case 72: // 9600 bit/s |
| 1119 | |
| 1120 | si2 += 5; |
| 1121 | break; |
| 1122 | case 73: // 14400 bit/s |
| 1123 | |
| 1124 | si2 += 6; |
| 1125 | break; |
| 1126 | case 75: // 19200 bit/s |
| 1127 | |
| 1128 | si2 += 7; |
| 1129 | break; |
| 1130 | } |
| 1131 | |
| 1132 | info = p[7] & 0x7f; |
| 1133 | if ((info & 16) && (!(info & 8))) // 7 data bits |
| 1134 | |
| 1135 | si2 += 32; // else 8 data bits |
| 1136 | |
| 1137 | if ((info & 96) == 96) // 2 stop bits |
| 1138 | |
| 1139 | si2 += 16; // else 1 stop bit |
| 1140 | |
| 1141 | if ((info & 2) && (!(info & 1))) // even parity |
| 1142 | |
| 1143 | si2 += 8; // else no parity |
| 1144 | |
| 1145 | return si2; |
| 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | static u_char |
| 1150 | DecodeSyncParams(u_char si2, u_char info) |
| 1151 | { |
| 1152 | info &= 0x7f; |
| 1153 | switch (info) { |
| 1154 | case 40: // bit/s negotiation failed ai := 165 not 175! |
| 1155 | |
| 1156 | return si2 + 15; |
| 1157 | case 15: // 56000 bit/s failed, ai := 0 not 169 ! |
| 1158 | |
| 1159 | return si2 + 9; |
| 1160 | case 14: // 48000 bit/s |
| 1161 | |
| 1162 | return si2 + 8; |
| 1163 | case 11: // 19200 bit/s |
| 1164 | |
| 1165 | return si2 + 7; |
| 1166 | case 9: // 14400 bit/s |
| 1167 | |
| 1168 | return si2 + 6; |
| 1169 | case 8: // 9600 bit/s |
| 1170 | |
| 1171 | return si2 + 5; |
| 1172 | case 5: // 4800 bit/s |
| 1173 | |
| 1174 | return si2 + 4; |
| 1175 | case 3: // 2400 bit/s |
| 1176 | |
| 1177 | return si2 + 3; |
| 1178 | case 23: // 75/1200 bit/s |
| 1179 | |
| 1180 | return si2 + 2; |
| 1181 | case 24: // 1200/75 bit/s |
| 1182 | |
| 1183 | return si2 + 1; |
| 1184 | default: // 1200 bit/s |
| 1185 | |
| 1186 | return si2; |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | static u_char |
| 1191 | DecodeSI2(struct sk_buff *skb) |
| 1192 | { |
| 1193 | u_char *p; //, *pend=skb->data + skb->len; |
| 1194 | |
| 1195 | if ((p = findie(skb->data, skb->len, 0x7c, 0))) { |
| 1196 | switch (p[4] & 0x0f) { |
| 1197 | case 0x01: |
| 1198 | if (p[1] == 0x04) // sync. Bitratenadaption |
| 1199 | |
| 1200 | return DecodeSyncParams(160, p[5]); // V.110/X.30 |
| 1201 | |
| 1202 | else if (p[1] == 0x06) // async. Bitratenadaption |
| 1203 | |
| 1204 | return DecodeASyncParams(192, p); // V.110/X.30 |
| 1205 | |
| 1206 | break; |
| 1207 | case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption |
| 1208 | if (p[1] > 3) |
| 1209 | return DecodeSyncParams(176, p[5]); // V.120 |
| 1210 | break; |
| 1211 | } |
| 1212 | } |
| 1213 | return 0; |
| 1214 | } |
| 1215 | |
| 1216 | #endif |
| 1217 | |
| 1218 | |
| 1219 | static void |
| 1220 | l3dss1_setup_req(struct l3_process *pc, u_char pr, |
| 1221 | void *arg) |
| 1222 | { |
| 1223 | struct sk_buff *skb; |
| 1224 | u_char tmp[128]; |
| 1225 | u_char *p = tmp; |
| 1226 | u_char channel = 0; |
| 1227 | |
| 1228 | u_char send_keypad; |
| 1229 | u_char screen = 0x80; |
| 1230 | u_char *teln; |
| 1231 | u_char *msn; |
| 1232 | u_char *sub; |
| 1233 | u_char *sp; |
| 1234 | int l; |
| 1235 | |
| 1236 | MsgHead(p, pc->callref, MT_SETUP); |
| 1237 | |
| 1238 | teln = pc->para.setup.phone; |
| 1239 | #ifndef CONFIG_HISAX_NO_KEYPAD |
| 1240 | send_keypad = (strchr(teln, '*') || strchr(teln, '#')) ? 1 : 0; |
| 1241 | #else |
| 1242 | send_keypad = 0; |
| 1243 | #endif |
| 1244 | #ifndef CONFIG_HISAX_NO_SENDCOMPLETE |
| 1245 | if (!send_keypad) |
| 1246 | *p++ = 0xa1; /* complete indicator */ |
| 1247 | #endif |
| 1248 | /* |
| 1249 | * Set Bearer Capability, Map info from 1TR6-convention to EDSS1 |
| 1250 | */ |
| 1251 | switch (pc->para.setup.si1) { |
| 1252 | case 1: /* Telephony */ |
| 1253 | *p++ = IE_BEARER; |
| 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 */ |
| 1258 | break; |
| 1259 | case 5: /* Datatransmission 64k, BTX */ |
| 1260 | case 7: /* Datatransmission 64k */ |
| 1261 | default: |
| 1262 | *p++ = IE_BEARER; |
| 1263 | *p++ = 0x2; /* Length */ |
| 1264 | *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */ |
| 1265 | *p++ = 0x90; /* Circuit-Mode 64kbps */ |
| 1266 | break; |
| 1267 | } |
| 1268 | |
| 1269 | if (send_keypad) { |
| 1270 | *p++ = IE_KEYPAD; |
| 1271 | *p++ = strlen(teln); |
| 1272 | while (*teln) |
| 1273 | *p++ = (*teln++) & 0x7F; |
| 1274 | } |
| 1275 | |
| 1276 | /* |
| 1277 | * What about info2? Mapping to High-Layer-Compatibility? |
| 1278 | */ |
| 1279 | if ((*teln) && (!send_keypad)) { |
| 1280 | /* parse number for special things */ |
| 1281 | if (!isdigit(*teln)) { |
| 1282 | switch (0x5f & *teln) { |
| 1283 | case 'C': |
| 1284 | channel = 0x08; |
| 1285 | /* fall through */ |
| 1286 | case 'P': |
| 1287 | channel |= 0x80; |
| 1288 | teln++; |
| 1289 | if (*teln == '1') |
| 1290 | channel |= 0x01; |
| 1291 | else |
| 1292 | channel |= 0x02; |
| 1293 | break; |
| 1294 | case 'R': |
| 1295 | screen = 0xA0; |
| 1296 | break; |
| 1297 | case 'D': |
| 1298 | screen = 0x80; |
| 1299 | break; |
| 1300 | |
| 1301 | default: |
| 1302 | if (pc->debug & L3_DEB_WARN) |
| 1303 | l3_debug(pc->st, "Wrong MSN Code"); |
| 1304 | break; |
| 1305 | } |
| 1306 | teln++; |
| 1307 | } |
| 1308 | } |
| 1309 | if (channel) { |
| 1310 | *p++ = IE_CHANNEL_ID; |
| 1311 | *p++ = 1; |
| 1312 | *p++ = channel; |
| 1313 | } |
| 1314 | msn = pc->para.setup.eazmsn; |
| 1315 | sub = NULL; |
| 1316 | sp = msn; |
| 1317 | while (*sp) { |
| 1318 | if ('.' == *sp) { |
| 1319 | sub = sp; |
| 1320 | *sp = 0; |
| 1321 | } else |
| 1322 | sp++; |
| 1323 | } |
| 1324 | if (*msn) { |
| 1325 | *p++ = IE_CALLING_PN; |
| 1326 | *p++ = strlen(msn) + (screen ? 2 : 1); |
| 1327 | /* Classify as AnyPref. */ |
| 1328 | if (screen) { |
| 1329 | *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */ |
| 1330 | *p++ = screen; |
| 1331 | } else |
| 1332 | *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */ |
| 1333 | while (*msn) |
| 1334 | *p++ = *msn++ & 0x7f; |
| 1335 | } |
| 1336 | if (sub) { |
| 1337 | *sub++ = '.'; |
| 1338 | *p++ = IE_CALLING_SUB; |
| 1339 | *p++ = strlen(sub) + 2; |
| 1340 | *p++ = 0x80; /* NSAP coded */ |
| 1341 | *p++ = 0x50; /* local IDI format */ |
| 1342 | while (*sub) |
| 1343 | *p++ = *sub++ & 0x7f; |
| 1344 | } |
| 1345 | sub = NULL; |
| 1346 | sp = teln; |
| 1347 | while (*sp) { |
| 1348 | if ('.' == *sp) { |
| 1349 | sub = sp; |
| 1350 | *sp = 0; |
| 1351 | } else |
| 1352 | sp++; |
| 1353 | } |
| 1354 | |
| 1355 | if (!send_keypad) { |
| 1356 | *p++ = IE_CALLED_PN; |
| 1357 | *p++ = strlen(teln) + 1; |
| 1358 | /* Classify as AnyPref. */ |
| 1359 | *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */ |
| 1360 | while (*teln) |
| 1361 | *p++ = *teln++ & 0x7f; |
| 1362 | |
| 1363 | if (sub) { |
| 1364 | *sub++ = '.'; |
| 1365 | *p++ = IE_CALLED_SUB; |
| 1366 | *p++ = strlen(sub) + 2; |
| 1367 | *p++ = 0x80; /* NSAP coded */ |
| 1368 | *p++ = 0x50; /* local IDI format */ |
| 1369 | while (*sub) |
| 1370 | *p++ = *sub++ & 0x7f; |
| 1371 | } |
| 1372 | } |
| 1373 | #ifdef EXT_BEARER_CAPS |
| 1374 | if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30 |
| 1375 | |
| 1376 | *p++ = IE_LLC; |
| 1377 | *p++ = 0x04; |
| 1378 | *p++ = 0x88; |
| 1379 | *p++ = 0x90; |
| 1380 | *p++ = 0x21; |
| 1381 | *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80); |
| 1382 | } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120 |
| 1383 | |
| 1384 | *p++ = IE_LLC; |
| 1385 | *p++ = 0x05; |
| 1386 | *p++ = 0x88; |
| 1387 | *p++ = 0x90; |
| 1388 | *p++ = 0x28; |
| 1389 | *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0); |
| 1390 | *p++ = 0x82; |
| 1391 | } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30 |
| 1392 | |
| 1393 | *p++ = IE_LLC; |
| 1394 | *p++ = 0x06; |
| 1395 | *p++ = 0x88; |
| 1396 | *p++ = 0x90; |
| 1397 | *p++ = 0x21; |
| 1398 | p = EncodeASyncParams(p, pc->para.setup.si2 - 192); |
| 1399 | #ifndef CONFIG_HISAX_NO_LLC |
| 1400 | } else { |
| 1401 | switch (pc->para.setup.si1) { |
| 1402 | case 1: /* Telephony */ |
| 1403 | *p++ = IE_LLC; |
| 1404 | *p++ = 0x3; /* Length */ |
| 1405 | *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */ |
| 1406 | *p++ = 0x90; /* Circuit-Mode 64kbps */ |
| 1407 | *p++ = 0xa3; /* A-Law Audio */ |
| 1408 | break; |
| 1409 | case 5: /* Datatransmission 64k, BTX */ |
| 1410 | case 7: /* Datatransmission 64k */ |
| 1411 | default: |
| 1412 | *p++ = IE_LLC; |
| 1413 | *p++ = 0x2; /* Length */ |
| 1414 | *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */ |
| 1415 | *p++ = 0x90; /* Circuit-Mode 64kbps */ |
| 1416 | break; |
| 1417 | } |
| 1418 | #endif |
| 1419 | } |
| 1420 | #endif |
| 1421 | l = p - tmp; |
| 1422 | if (!(skb = l3_alloc_skb(l))) |
| 1423 | return; |
| 1424 | skb_put_data(skb, tmp, l); |
| 1425 | L3DelTimer(&pc->timer); |
| 1426 | L3AddTimer(&pc->timer, T303, CC_T303); |
| 1427 | newl3state(pc, 1); |
| 1428 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 1429 | } |
| 1430 | |
| 1431 | static void |
| 1432 | l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg) |
| 1433 | { |
| 1434 | struct sk_buff *skb = arg; |
| 1435 | int id, ret; |
| 1436 | |
| 1437 | if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) { |
| 1438 | if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) { |
| 1439 | if (pc->debug & L3_DEB_WARN) |
| 1440 | l3_debug(pc->st, "setup answer with wrong chid %x", id); |
| 1441 | pc->para.cause = 100; |
| 1442 | l3dss1_status_send(pc, pr, NULL); |
| 1443 | return; |
| 1444 | } |
| 1445 | pc->para.bchannel = id; |
| 1446 | } else if (1 == pc->state) { |
| 1447 | if (pc->debug & L3_DEB_WARN) |
| 1448 | l3_debug(pc->st, "setup answer wrong chid (ret %d)", id); |
| 1449 | if (id == -1) |
| 1450 | pc->para.cause = 96; |
| 1451 | else |
| 1452 | pc->para.cause = 100; |
| 1453 | l3dss1_status_send(pc, pr, NULL); |
| 1454 | return; |
| 1455 | } |
| 1456 | /* Now we are on none mandatory IEs */ |
| 1457 | ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING); |
| 1458 | if (ERR_IE_COMPREHENSION == ret) { |
| 1459 | l3dss1_std_ie_err(pc, ret); |
| 1460 | return; |
| 1461 | } |
| 1462 | L3DelTimer(&pc->timer); |
| 1463 | newl3state(pc, 3); |
| 1464 | L3AddTimer(&pc->timer, T310, CC_T310); |
| 1465 | if (ret) /* STATUS for none mandatory IE errors after actions are taken */ |
| 1466 | l3dss1_std_ie_err(pc, ret); |
| 1467 | pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc); |
| 1468 | } |
| 1469 | |
| 1470 | static void |
| 1471 | l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg) |
| 1472 | { |
| 1473 | struct sk_buff *skb = arg; |
| 1474 | int id, ret; |
| 1475 | |
| 1476 | if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) { |
| 1477 | if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) { |
| 1478 | if (pc->debug & L3_DEB_WARN) |
| 1479 | l3_debug(pc->st, "setup answer with wrong chid %x", id); |
| 1480 | pc->para.cause = 100; |
| 1481 | l3dss1_status_send(pc, pr, NULL); |
| 1482 | return; |
| 1483 | } |
| 1484 | pc->para.bchannel = id; |
| 1485 | } else { |
| 1486 | if (pc->debug & L3_DEB_WARN) |
| 1487 | l3_debug(pc->st, "setup answer wrong chid (ret %d)", id); |
| 1488 | if (id == -1) |
| 1489 | pc->para.cause = 96; |
| 1490 | else |
| 1491 | pc->para.cause = 100; |
| 1492 | l3dss1_status_send(pc, pr, NULL); |
| 1493 | return; |
| 1494 | } |
| 1495 | /* Now we are on none mandatory IEs */ |
| 1496 | ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE); |
| 1497 | if (ERR_IE_COMPREHENSION == ret) { |
| 1498 | l3dss1_std_ie_err(pc, ret); |
| 1499 | return; |
| 1500 | } |
| 1501 | L3DelTimer(&pc->timer); |
| 1502 | newl3state(pc, 2); |
| 1503 | L3AddTimer(&pc->timer, T304, CC_T304); |
| 1504 | if (ret) /* STATUS for none mandatory IE errors after actions are taken */ |
| 1505 | l3dss1_std_ie_err(pc, ret); |
| 1506 | pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc); |
| 1507 | } |
| 1508 | |
| 1509 | static void |
| 1510 | l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg) |
| 1511 | { |
| 1512 | struct sk_buff *skb = arg; |
| 1513 | u_char *p; |
| 1514 | int ret; |
| 1515 | u_char cause = 0; |
| 1516 | |
| 1517 | StopAllL3Timer(pc); |
| 1518 | if ((ret = l3dss1_get_cause(pc, skb))) { |
| 1519 | if (pc->debug & L3_DEB_WARN) |
| 1520 | l3_debug(pc->st, "DISC get_cause ret(%d)", ret); |
| 1521 | if (ret < 0) |
| 1522 | cause = 96; |
| 1523 | else if (ret > 0) |
| 1524 | cause = 100; |
| 1525 | } |
| 1526 | if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) |
| 1527 | l3dss1_parse_facility(pc->st, pc, pc->callref, p); |
| 1528 | ret = check_infoelements(pc, skb, ie_DISCONNECT); |
| 1529 | if (ERR_IE_COMPREHENSION == ret) |
| 1530 | cause = 96; |
| 1531 | else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret)) |
| 1532 | cause = 99; |
| 1533 | ret = pc->state; |
| 1534 | newl3state(pc, 12); |
| 1535 | if (cause) |
| 1536 | newl3state(pc, 19); |
| 1537 | if (11 != ret) |
| 1538 | pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc); |
| 1539 | else if (!cause) |
| 1540 | l3dss1_release_req(pc, pr, NULL); |
| 1541 | if (cause) { |
| 1542 | l3dss1_message_cause(pc, MT_RELEASE, cause); |
| 1543 | L3AddTimer(&pc->timer, T308, CC_T308_1); |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | static void |
| 1548 | l3dss1_connect(struct l3_process *pc, u_char pr, void *arg) |
| 1549 | { |
| 1550 | struct sk_buff *skb = arg; |
| 1551 | int ret; |
| 1552 | |
| 1553 | ret = check_infoelements(pc, skb, ie_CONNECT); |
| 1554 | if (ERR_IE_COMPREHENSION == ret) { |
| 1555 | l3dss1_std_ie_err(pc, ret); |
| 1556 | return; |
| 1557 | } |
| 1558 | L3DelTimer(&pc->timer); /* T310 */ |
| 1559 | newl3state(pc, 10); |
| 1560 | pc->para.chargeinfo = 0; |
| 1561 | /* here should inserted COLP handling KKe */ |
| 1562 | if (ret) |
| 1563 | l3dss1_std_ie_err(pc, ret); |
| 1564 | pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc); |
| 1565 | } |
| 1566 | |
| 1567 | static void |
| 1568 | l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg) |
| 1569 | { |
| 1570 | struct sk_buff *skb = arg; |
| 1571 | int ret; |
| 1572 | |
| 1573 | ret = check_infoelements(pc, skb, ie_ALERTING); |
| 1574 | if (ERR_IE_COMPREHENSION == ret) { |
| 1575 | l3dss1_std_ie_err(pc, ret); |
| 1576 | return; |
| 1577 | } |
| 1578 | L3DelTimer(&pc->timer); /* T304 */ |
| 1579 | newl3state(pc, 4); |
| 1580 | if (ret) |
| 1581 | l3dss1_std_ie_err(pc, ret); |
| 1582 | pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc); |
| 1583 | } |
| 1584 | |
| 1585 | static void |
| 1586 | l3dss1_setup(struct l3_process *pc, u_char pr, void *arg) |
| 1587 | { |
| 1588 | u_char *p; |
| 1589 | int bcfound = 0; |
| 1590 | char tmp[80]; |
| 1591 | struct sk_buff *skb = arg; |
| 1592 | int id; |
| 1593 | int err = 0; |
| 1594 | |
| 1595 | /* |
| 1596 | * Bearer Capabilities |
| 1597 | */ |
| 1598 | p = skb->data; |
| 1599 | /* only the first occurrence 'll be detected ! */ |
| 1600 | if ((p = findie(p, skb->len, 0x04, 0))) { |
| 1601 | if ((p[1] < 2) || (p[1] > 11)) |
| 1602 | err = 1; |
| 1603 | else { |
| 1604 | pc->para.setup.si2 = 0; |
| 1605 | switch (p[2] & 0x7f) { |
| 1606 | case 0x00: /* Speech */ |
| 1607 | case 0x10: /* 3.1 Khz audio */ |
| 1608 | pc->para.setup.si1 = 1; |
| 1609 | break; |
| 1610 | case 0x08: /* Unrestricted digital information */ |
| 1611 | pc->para.setup.si1 = 7; |
| 1612 | /* JIM, 05.11.97 I wanna set service indicator 2 */ |
| 1613 | #ifdef EXT_BEARER_CAPS |
| 1614 | pc->para.setup.si2 = DecodeSI2(skb); |
| 1615 | #endif |
| 1616 | break; |
| 1617 | case 0x09: /* Restricted digital information */ |
| 1618 | pc->para.setup.si1 = 2; |
| 1619 | break; |
| 1620 | case 0x11: |
| 1621 | /* Unrestr. digital information with |
| 1622 | * tones/announcements ( or 7 kHz audio |
| 1623 | */ |
| 1624 | pc->para.setup.si1 = 3; |
| 1625 | break; |
| 1626 | case 0x18: /* Video */ |
| 1627 | pc->para.setup.si1 = 4; |
| 1628 | break; |
| 1629 | default: |
| 1630 | err = 2; |
| 1631 | break; |
| 1632 | } |
| 1633 | switch (p[3] & 0x7f) { |
| 1634 | case 0x40: /* packed mode */ |
| 1635 | pc->para.setup.si1 = 8; |
| 1636 | break; |
| 1637 | case 0x10: /* 64 kbit */ |
| 1638 | case 0x11: /* 2*64 kbit */ |
| 1639 | case 0x13: /* 384 kbit */ |
| 1640 | case 0x15: /* 1536 kbit */ |
| 1641 | case 0x17: /* 1920 kbit */ |
| 1642 | pc->para.moderate = p[3] & 0x7f; |
| 1643 | break; |
| 1644 | default: |
| 1645 | err = 3; |
| 1646 | break; |
| 1647 | } |
| 1648 | } |
| 1649 | if (pc->debug & L3_DEB_SI) |
| 1650 | l3_debug(pc->st, "SI=%d, AI=%d", |
| 1651 | pc->para.setup.si1, pc->para.setup.si2); |
| 1652 | if (err) { |
| 1653 | if (pc->debug & L3_DEB_WARN) |
| 1654 | l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)", |
| 1655 | p[1], p[2], p[3]); |
| 1656 | pc->para.cause = 100; |
| 1657 | l3dss1_msg_without_setup(pc, pr, NULL); |
| 1658 | return; |
| 1659 | } |
| 1660 | } else { |
| 1661 | if (pc->debug & L3_DEB_WARN) |
| 1662 | l3_debug(pc->st, "setup without bearer capabilities"); |
| 1663 | /* ETS 300-104 1.3.3 */ |
| 1664 | pc->para.cause = 96; |
| 1665 | l3dss1_msg_without_setup(pc, pr, NULL); |
| 1666 | return; |
| 1667 | } |
| 1668 | /* |
| 1669 | * Channel Identification |
| 1670 | */ |
| 1671 | if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) { |
| 1672 | if ((pc->para.bchannel = id)) { |
| 1673 | if ((3 == id) && (0x10 == pc->para.moderate)) { |
| 1674 | if (pc->debug & L3_DEB_WARN) |
| 1675 | l3_debug(pc->st, "setup with wrong chid %x", |
| 1676 | id); |
| 1677 | pc->para.cause = 100; |
| 1678 | l3dss1_msg_without_setup(pc, pr, NULL); |
| 1679 | return; |
| 1680 | } |
| 1681 | bcfound++; |
| 1682 | } else |
| 1683 | { if (pc->debug & L3_DEB_WARN) |
| 1684 | l3_debug(pc->st, "setup without bchannel, call waiting"); |
| 1685 | bcfound++; |
| 1686 | } |
| 1687 | } else { |
| 1688 | if (pc->debug & L3_DEB_WARN) |
| 1689 | l3_debug(pc->st, "setup with wrong chid ret %d", id); |
| 1690 | if (id == -1) |
| 1691 | pc->para.cause = 96; |
| 1692 | else |
| 1693 | pc->para.cause = 100; |
| 1694 | l3dss1_msg_without_setup(pc, pr, NULL); |
| 1695 | return; |
| 1696 | } |
| 1697 | /* Now we are on none mandatory IEs */ |
| 1698 | err = check_infoelements(pc, skb, ie_SETUP); |
| 1699 | if (ERR_IE_COMPREHENSION == err) { |
| 1700 | pc->para.cause = 96; |
| 1701 | l3dss1_msg_without_setup(pc, pr, NULL); |
| 1702 | return; |
| 1703 | } |
| 1704 | p = skb->data; |
| 1705 | if ((p = findie(p, skb->len, 0x70, 0))) |
| 1706 | iecpy(pc->para.setup.eazmsn, p, 1); |
| 1707 | else |
| 1708 | pc->para.setup.eazmsn[0] = 0; |
| 1709 | |
| 1710 | p = skb->data; |
| 1711 | if ((p = findie(p, skb->len, 0x71, 0))) { |
| 1712 | /* Called party subaddress */ |
| 1713 | if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) { |
| 1714 | tmp[0] = '.'; |
| 1715 | iecpy(&tmp[1], p, 2); |
| 1716 | strcat(pc->para.setup.eazmsn, tmp); |
| 1717 | } else if (pc->debug & L3_DEB_WARN) |
| 1718 | l3_debug(pc->st, "wrong called subaddress"); |
| 1719 | } |
| 1720 | p = skb->data; |
| 1721 | if ((p = findie(p, skb->len, 0x6c, 0))) { |
| 1722 | pc->para.setup.plan = p[2]; |
| 1723 | if (p[2] & 0x80) { |
| 1724 | iecpy(pc->para.setup.phone, p, 1); |
| 1725 | pc->para.setup.screen = 0; |
| 1726 | } else { |
| 1727 | iecpy(pc->para.setup.phone, p, 2); |
| 1728 | pc->para.setup.screen = p[3]; |
| 1729 | } |
| 1730 | } else { |
| 1731 | pc->para.setup.phone[0] = 0; |
| 1732 | pc->para.setup.plan = 0; |
| 1733 | pc->para.setup.screen = 0; |
| 1734 | } |
| 1735 | p = skb->data; |
| 1736 | if ((p = findie(p, skb->len, 0x6d, 0))) { |
| 1737 | /* Calling party subaddress */ |
| 1738 | if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) { |
| 1739 | tmp[0] = '.'; |
| 1740 | iecpy(&tmp[1], p, 2); |
| 1741 | strcat(pc->para.setup.phone, tmp); |
| 1742 | } else if (pc->debug & L3_DEB_WARN) |
| 1743 | l3_debug(pc->st, "wrong calling subaddress"); |
| 1744 | } |
| 1745 | newl3state(pc, 6); |
| 1746 | if (err) /* STATUS for none mandatory IE errors after actions are taken */ |
| 1747 | l3dss1_std_ie_err(pc, err); |
| 1748 | pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc); |
| 1749 | } |
| 1750 | |
| 1751 | static void |
| 1752 | l3dss1_reset(struct l3_process *pc, u_char pr, void *arg) |
| 1753 | { |
| 1754 | dss1_release_l3_process(pc); |
| 1755 | } |
| 1756 | |
| 1757 | static void |
| 1758 | l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg) |
| 1759 | { |
| 1760 | struct sk_buff *skb; |
| 1761 | u_char tmp[16 + 40]; |
| 1762 | u_char *p = tmp; |
| 1763 | int l; |
| 1764 | u_char cause = 16; |
| 1765 | |
| 1766 | if (pc->para.cause != NO_CAUSE) |
| 1767 | cause = pc->para.cause; |
| 1768 | |
| 1769 | StopAllL3Timer(pc); |
| 1770 | |
| 1771 | MsgHead(p, pc->callref, MT_DISCONNECT); |
| 1772 | |
| 1773 | *p++ = IE_CAUSE; |
| 1774 | *p++ = 0x2; |
| 1775 | *p++ = 0x80; |
| 1776 | *p++ = cause | 0x80; |
| 1777 | |
| 1778 | if (pc->prot.dss1.uus1_data[0]) |
| 1779 | { *p++ = IE_USER_USER; /* UUS info element */ |
| 1780 | *p++ = strlen(pc->prot.dss1.uus1_data) + 1; |
| 1781 | *p++ = 0x04; /* IA5 chars */ |
| 1782 | strcpy(p, pc->prot.dss1.uus1_data); |
| 1783 | p += strlen(pc->prot.dss1.uus1_data); |
| 1784 | pc->prot.dss1.uus1_data[0] = '\0'; |
| 1785 | } |
| 1786 | |
| 1787 | l = p - tmp; |
| 1788 | if (!(skb = l3_alloc_skb(l))) |
| 1789 | return; |
| 1790 | skb_put_data(skb, tmp, l); |
| 1791 | newl3state(pc, 11); |
| 1792 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 1793 | L3AddTimer(&pc->timer, T305, CC_T305); |
| 1794 | } |
| 1795 | |
| 1796 | static void |
| 1797 | l3dss1_setup_rsp(struct l3_process *pc, u_char pr, |
| 1798 | void *arg) |
| 1799 | { |
| 1800 | if (!pc->para.bchannel) |
| 1801 | { if (pc->debug & L3_DEB_WARN) |
| 1802 | l3_debug(pc->st, "D-chan connect for waiting call"); |
| 1803 | l3dss1_disconnect_req(pc, pr, arg); |
| 1804 | return; |
| 1805 | } |
| 1806 | newl3state(pc, 8); |
| 1807 | l3dss1_message(pc, MT_CONNECT); |
| 1808 | L3DelTimer(&pc->timer); |
| 1809 | L3AddTimer(&pc->timer, T313, CC_T313); |
| 1810 | } |
| 1811 | |
| 1812 | static void |
| 1813 | l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg) |
| 1814 | { |
| 1815 | struct sk_buff *skb = arg; |
| 1816 | int ret; |
| 1817 | |
| 1818 | ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE); |
| 1819 | if (ERR_IE_COMPREHENSION == ret) { |
| 1820 | l3dss1_std_ie_err(pc, ret); |
| 1821 | return; |
| 1822 | } |
| 1823 | newl3state(pc, 10); |
| 1824 | L3DelTimer(&pc->timer); |
| 1825 | if (ret) |
| 1826 | l3dss1_std_ie_err(pc, ret); |
| 1827 | pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc); |
| 1828 | } |
| 1829 | |
| 1830 | static void |
| 1831 | l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg) |
| 1832 | { |
| 1833 | struct sk_buff *skb; |
| 1834 | u_char tmp[16]; |
| 1835 | u_char *p = tmp; |
| 1836 | int l; |
| 1837 | u_char cause = 21; |
| 1838 | |
| 1839 | if (pc->para.cause != NO_CAUSE) |
| 1840 | cause = pc->para.cause; |
| 1841 | |
| 1842 | MsgHead(p, pc->callref, MT_RELEASE_COMPLETE); |
| 1843 | |
| 1844 | *p++ = IE_CAUSE; |
| 1845 | *p++ = 0x2; |
| 1846 | *p++ = 0x80; |
| 1847 | *p++ = cause | 0x80; |
| 1848 | |
| 1849 | l = p - tmp; |
| 1850 | if (!(skb = l3_alloc_skb(l))) |
| 1851 | return; |
| 1852 | skb_put_data(skb, tmp, l); |
| 1853 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 1854 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 1855 | newl3state(pc, 0); |
| 1856 | dss1_release_l3_process(pc); |
| 1857 | } |
| 1858 | |
| 1859 | static void |
| 1860 | l3dss1_release(struct l3_process *pc, u_char pr, void *arg) |
| 1861 | { |
| 1862 | struct sk_buff *skb = arg; |
| 1863 | u_char *p; |
| 1864 | int ret, cause = 0; |
| 1865 | |
| 1866 | StopAllL3Timer(pc); |
| 1867 | if ((ret = l3dss1_get_cause(pc, skb)) > 0) { |
| 1868 | if (pc->debug & L3_DEB_WARN) |
| 1869 | l3_debug(pc->st, "REL get_cause ret(%d)", ret); |
| 1870 | } else if (ret < 0) |
| 1871 | pc->para.cause = NO_CAUSE; |
| 1872 | if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) { |
| 1873 | l3dss1_parse_facility(pc->st, pc, pc->callref, p); |
| 1874 | } |
| 1875 | if ((ret < 0) && (pc->state != 11)) |
| 1876 | cause = 96; |
| 1877 | else if (ret > 0) |
| 1878 | cause = 100; |
| 1879 | ret = check_infoelements(pc, skb, ie_RELEASE); |
| 1880 | if (ERR_IE_COMPREHENSION == ret) |
| 1881 | cause = 96; |
| 1882 | else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause)) |
| 1883 | cause = 99; |
| 1884 | if (cause) |
| 1885 | l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause); |
| 1886 | else |
| 1887 | l3dss1_message(pc, MT_RELEASE_COMPLETE); |
| 1888 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 1889 | newl3state(pc, 0); |
| 1890 | dss1_release_l3_process(pc); |
| 1891 | } |
| 1892 | |
| 1893 | static void |
| 1894 | l3dss1_alert_req(struct l3_process *pc, u_char pr, |
| 1895 | void *arg) |
| 1896 | { |
| 1897 | newl3state(pc, 7); |
| 1898 | if (!pc->prot.dss1.uus1_data[0]) |
| 1899 | l3dss1_message(pc, MT_ALERTING); |
| 1900 | else |
| 1901 | l3dss1_msg_with_uus(pc, MT_ALERTING); |
| 1902 | } |
| 1903 | |
| 1904 | static void |
| 1905 | l3dss1_proceed_req(struct l3_process *pc, u_char pr, |
| 1906 | void *arg) |
| 1907 | { |
| 1908 | newl3state(pc, 9); |
| 1909 | l3dss1_message(pc, MT_CALL_PROCEEDING); |
| 1910 | pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc); |
| 1911 | } |
| 1912 | |
| 1913 | static void |
| 1914 | l3dss1_setup_ack_req(struct l3_process *pc, u_char pr, |
| 1915 | void *arg) |
| 1916 | { |
| 1917 | newl3state(pc, 25); |
| 1918 | L3DelTimer(&pc->timer); |
| 1919 | L3AddTimer(&pc->timer, T302, CC_T302); |
| 1920 | l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE); |
| 1921 | } |
| 1922 | |
| 1923 | /********************************************/ |
| 1924 | /* deliver a incoming display message to HL */ |
| 1925 | /********************************************/ |
| 1926 | static void |
| 1927 | l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp) |
| 1928 | { u_char len; |
| 1929 | isdn_ctrl ic; |
| 1930 | struct IsdnCardState *cs; |
| 1931 | char *p; |
| 1932 | |
| 1933 | if (*infp++ != IE_DISPLAY) return; |
| 1934 | if ((len = *infp++) > 80) return; /* total length <= 82 */ |
| 1935 | if (!pc->chan) return; |
| 1936 | |
| 1937 | p = ic.parm.display; |
| 1938 | while (len--) |
| 1939 | *p++ = *infp++; |
| 1940 | *p = '\0'; |
| 1941 | ic.command = ISDN_STAT_DISPLAY; |
| 1942 | cs = pc->st->l1.hardware; |
| 1943 | ic.driver = cs->myid; |
| 1944 | ic.arg = pc->chan->chan; |
| 1945 | cs->iif.statcallb(&ic); |
| 1946 | } /* l3dss1_deliver_display */ |
| 1947 | |
| 1948 | |
| 1949 | static void |
| 1950 | l3dss1_progress(struct l3_process *pc, u_char pr, void *arg) |
| 1951 | { |
| 1952 | struct sk_buff *skb = arg; |
| 1953 | int err = 0; |
| 1954 | u_char *p; |
| 1955 | |
| 1956 | if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) { |
| 1957 | if (p[1] != 2) { |
| 1958 | err = 1; |
| 1959 | pc->para.cause = 100; |
| 1960 | } else if (!(p[2] & 0x70)) { |
| 1961 | switch (p[2]) { |
| 1962 | case 0x80: |
| 1963 | case 0x81: |
| 1964 | case 0x82: |
| 1965 | case 0x84: |
| 1966 | case 0x85: |
| 1967 | case 0x87: |
| 1968 | case 0x8a: |
| 1969 | switch (p[3]) { |
| 1970 | case 0x81: |
| 1971 | case 0x82: |
| 1972 | case 0x83: |
| 1973 | case 0x84: |
| 1974 | case 0x88: |
| 1975 | break; |
| 1976 | default: |
| 1977 | err = 2; |
| 1978 | pc->para.cause = 100; |
| 1979 | break; |
| 1980 | } |
| 1981 | break; |
| 1982 | default: |
| 1983 | err = 3; |
| 1984 | pc->para.cause = 100; |
| 1985 | break; |
| 1986 | } |
| 1987 | } |
| 1988 | } else { |
| 1989 | pc->para.cause = 96; |
| 1990 | err = 4; |
| 1991 | } |
| 1992 | if (err) { |
| 1993 | if (pc->debug & L3_DEB_WARN) |
| 1994 | l3_debug(pc->st, "progress error %d", err); |
| 1995 | l3dss1_status_send(pc, pr, NULL); |
| 1996 | return; |
| 1997 | } |
| 1998 | /* Now we are on none mandatory IEs */ |
| 1999 | err = check_infoelements(pc, skb, ie_PROGRESS); |
| 2000 | if (err) |
| 2001 | l3dss1_std_ie_err(pc, err); |
| 2002 | if (ERR_IE_COMPREHENSION != err) |
| 2003 | pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc); |
| 2004 | } |
| 2005 | |
| 2006 | static void |
| 2007 | l3dss1_notify(struct l3_process *pc, u_char pr, void *arg) |
| 2008 | { |
| 2009 | struct sk_buff *skb = arg; |
| 2010 | int err = 0; |
| 2011 | u_char *p; |
| 2012 | |
| 2013 | if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) { |
| 2014 | if (p[1] != 1) { |
| 2015 | err = 1; |
| 2016 | pc->para.cause = 100; |
| 2017 | } else { |
| 2018 | switch (p[2]) { |
| 2019 | case 0x80: |
| 2020 | case 0x81: |
| 2021 | case 0x82: |
| 2022 | break; |
| 2023 | default: |
| 2024 | pc->para.cause = 100; |
| 2025 | err = 2; |
| 2026 | break; |
| 2027 | } |
| 2028 | } |
| 2029 | } else { |
| 2030 | pc->para.cause = 96; |
| 2031 | err = 3; |
| 2032 | } |
| 2033 | if (err) { |
| 2034 | if (pc->debug & L3_DEB_WARN) |
| 2035 | l3_debug(pc->st, "notify error %d", err); |
| 2036 | l3dss1_status_send(pc, pr, NULL); |
| 2037 | return; |
| 2038 | } |
| 2039 | /* Now we are on none mandatory IEs */ |
| 2040 | err = check_infoelements(pc, skb, ie_NOTIFY); |
| 2041 | if (err) |
| 2042 | l3dss1_std_ie_err(pc, err); |
| 2043 | if (ERR_IE_COMPREHENSION != err) |
| 2044 | pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc); |
| 2045 | } |
| 2046 | |
| 2047 | static void |
| 2048 | l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg) |
| 2049 | { |
| 2050 | int ret; |
| 2051 | struct sk_buff *skb = arg; |
| 2052 | |
| 2053 | ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY); |
| 2054 | l3dss1_std_ie_err(pc, ret); |
| 2055 | pc->para.cause = 30; /* response to STATUS_ENQUIRY */ |
| 2056 | l3dss1_status_send(pc, pr, NULL); |
| 2057 | } |
| 2058 | |
| 2059 | static void |
| 2060 | l3dss1_information(struct l3_process *pc, u_char pr, void *arg) |
| 2061 | { |
| 2062 | int ret; |
| 2063 | struct sk_buff *skb = arg; |
| 2064 | u_char *p; |
| 2065 | char tmp[32]; |
| 2066 | |
| 2067 | ret = check_infoelements(pc, skb, ie_INFORMATION); |
| 2068 | if (ret) |
| 2069 | l3dss1_std_ie_err(pc, ret); |
| 2070 | if (pc->state == 25) { /* overlap receiving */ |
| 2071 | L3DelTimer(&pc->timer); |
| 2072 | p = skb->data; |
| 2073 | if ((p = findie(p, skb->len, 0x70, 0))) { |
| 2074 | iecpy(tmp, p, 1); |
| 2075 | strcat(pc->para.setup.eazmsn, tmp); |
| 2076 | pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc); |
| 2077 | } |
| 2078 | L3AddTimer(&pc->timer, T302, CC_T302); |
| 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | /******************************/ |
| 2083 | /* handle deflection requests */ |
| 2084 | /******************************/ |
| 2085 | static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg) |
| 2086 | { |
| 2087 | struct sk_buff *skb; |
| 2088 | u_char tmp[128]; |
| 2089 | u_char *p = tmp; |
| 2090 | u_char *subp; |
| 2091 | u_char len_phone = 0; |
| 2092 | u_char len_sub = 0; |
| 2093 | int l; |
| 2094 | |
| 2095 | |
| 2096 | strcpy(pc->prot.dss1.uus1_data, pc->chan->setup.eazmsn); /* copy uus element if available */ |
| 2097 | if (!pc->chan->setup.phone[0]) |
| 2098 | { pc->para.cause = -1; |
| 2099 | l3dss1_disconnect_req(pc, pr, arg); /* disconnect immediately */ |
| 2100 | return; |
| 2101 | } /* only uus */ |
| 2102 | |
| 2103 | if (pc->prot.dss1.invoke_id) |
| 2104 | free_invoke_id(pc->st, pc->prot.dss1.invoke_id); |
| 2105 | |
| 2106 | if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st))) |
| 2107 | return; |
| 2108 | |
| 2109 | MsgHead(p, pc->callref, MT_FACILITY); |
| 2110 | |
| 2111 | for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */ |
| 2112 | if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */ |
| 2113 | |
| 2114 | *p++ = 0x1c; /* Facility info element */ |
| 2115 | *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */ |
| 2116 | *p++ = 0x91; /* remote operations protocol */ |
| 2117 | *p++ = 0xa1; /* invoke component */ |
| 2118 | |
| 2119 | *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */ |
| 2120 | *p++ = 0x02; /* invoke id tag, integer */ |
| 2121 | *p++ = 0x01; /* length */ |
| 2122 | *p++ = pc->prot.dss1.invoke_id; /* invoke id */ |
| 2123 | *p++ = 0x02; /* operation value tag, integer */ |
| 2124 | *p++ = 0x01; /* length */ |
| 2125 | *p++ = 0x0D; /* Call Deflect */ |
| 2126 | |
| 2127 | *p++ = 0x30; /* sequence phone number */ |
| 2128 | *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */ |
| 2129 | |
| 2130 | *p++ = 0x30; /* Deflected to UserNumber */ |
| 2131 | *p++ = len_phone + 2 + len_sub; /* length */ |
| 2132 | *p++ = 0x80; /* NumberDigits */ |
| 2133 | *p++ = len_phone; /* length */ |
| 2134 | for (l = 0; l < len_phone; l++) |
| 2135 | *p++ = pc->chan->setup.phone[l]; |
| 2136 | |
| 2137 | if (len_sub) |
| 2138 | { *p++ = 0x04; /* called party subaddress */ |
| 2139 | *p++ = len_sub - 2; |
| 2140 | while (*subp) *p++ = *subp++; |
| 2141 | } |
| 2142 | |
| 2143 | *p++ = 0x01; /* screening identifier */ |
| 2144 | *p++ = 0x01; |
| 2145 | *p++ = pc->chan->setup.screen; |
| 2146 | |
| 2147 | l = p - tmp; |
| 2148 | if (!(skb = l3_alloc_skb(l))) return; |
| 2149 | skb_put_data(skb, tmp, l); |
| 2150 | |
| 2151 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 2152 | } /* l3dss1_redir_req */ |
| 2153 | |
| 2154 | /********************************************/ |
| 2155 | /* handle deflection request in early state */ |
| 2156 | /********************************************/ |
| 2157 | static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg) |
| 2158 | { |
| 2159 | l3dss1_proceed_req(pc, pr, arg); |
| 2160 | l3dss1_redir_req(pc, pr, arg); |
| 2161 | } /* l3dss1_redir_req_early */ |
| 2162 | |
| 2163 | /***********************************************/ |
| 2164 | /* handle special commands for this protocol. */ |
| 2165 | /* Examples are call independent services like */ |
| 2166 | /* remote operations with dummy callref. */ |
| 2167 | /***********************************************/ |
| 2168 | static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic) |
| 2169 | { u_char id; |
| 2170 | u_char temp[265]; |
| 2171 | u_char *p = temp; |
| 2172 | int i, l, proc_len; |
| 2173 | struct sk_buff *skb; |
| 2174 | struct l3_process *pc = NULL; |
| 2175 | |
| 2176 | switch (ic->arg) |
| 2177 | { case DSS1_CMD_INVOKE: |
| 2178 | if (ic->parm.dss1_io.datalen < 0) return (-2); /* invalid parameter */ |
| 2179 | |
| 2180 | for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++) |
| 2181 | i = i >> 8; /* add one byte */ |
| 2182 | l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */ |
| 2183 | if (l > 255) |
| 2184 | return (-2); /* too long */ |
| 2185 | |
| 2186 | if (!(id = new_invoke_id(st))) |
| 2187 | return (0); /* first get a invoke id -> return if no available */ |
| 2188 | |
| 2189 | i = -1; |
| 2190 | MsgHead(p, i, MT_FACILITY); /* build message head */ |
| 2191 | *p++ = 0x1C; /* Facility IE */ |
| 2192 | *p++ = l; /* length of ie */ |
| 2193 | *p++ = 0x91; /* remote operations */ |
| 2194 | *p++ = 0xA1; /* invoke */ |
| 2195 | *p++ = l - 3; /* length of invoke */ |
| 2196 | *p++ = 0x02; /* invoke id tag */ |
| 2197 | *p++ = 0x01; /* length is 1 */ |
| 2198 | *p++ = id; /* invoke id */ |
| 2199 | *p++ = 0x02; /* operation */ |
| 2200 | *p++ = proc_len; /* length of operation */ |
| 2201 | |
| 2202 | for (i = proc_len; i; i--) |
| 2203 | *p++ = (ic->parm.dss1_io.proc >> (i - 1)) & 0xFF; |
| 2204 | memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */ |
| 2205 | l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */ |
| 2206 | |
| 2207 | if (ic->parm.dss1_io.timeout > 0) |
| 2208 | if (!(pc = dss1_new_l3_process(st, -1))) |
| 2209 | { free_invoke_id(st, id); |
| 2210 | return (-2); |
| 2211 | } |
| 2212 | pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */ |
| 2213 | pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */ |
| 2214 | |
| 2215 | if (!(skb = l3_alloc_skb(l))) |
| 2216 | { free_invoke_id(st, id); |
| 2217 | if (pc) dss1_release_l3_process(pc); |
| 2218 | return (-2); |
| 2219 | } |
| 2220 | skb_put_data(skb, temp, l); |
| 2221 | |
| 2222 | if (pc) |
| 2223 | { pc->prot.dss1.invoke_id = id; /* remember id */ |
| 2224 | L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST); |
| 2225 | } |
| 2226 | |
| 2227 | l3_msg(st, DL_DATA | REQUEST, skb); |
| 2228 | ic->parm.dss1_io.hl_id = id; /* return id */ |
| 2229 | return (0); |
| 2230 | |
| 2231 | case DSS1_CMD_INVOKE_ABORT: |
| 2232 | if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id))) |
| 2233 | { L3DelTimer(&pc->timer); /* remove timer */ |
| 2234 | dss1_release_l3_process(pc); |
| 2235 | return (0); |
| 2236 | } |
| 2237 | else |
| 2238 | { l3_debug(st, "l3dss1_cmd_global abort unknown id"); |
| 2239 | return (-2); |
| 2240 | } |
| 2241 | break; |
| 2242 | |
| 2243 | default: |
| 2244 | l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg); |
| 2245 | return (-1); |
| 2246 | } /* switch ic-> arg */ |
| 2247 | return (-1); |
| 2248 | } /* l3dss1_cmd_global */ |
| 2249 | |
| 2250 | static void |
| 2251 | l3dss1_io_timer(struct l3_process *pc) |
| 2252 | { isdn_ctrl ic; |
| 2253 | struct IsdnCardState *cs = pc->st->l1.hardware; |
| 2254 | |
| 2255 | L3DelTimer(&pc->timer); /* remove timer */ |
| 2256 | |
| 2257 | ic.driver = cs->myid; |
| 2258 | ic.command = ISDN_STAT_PROT; |
| 2259 | ic.arg = DSS1_STAT_INVOKE_ERR; |
| 2260 | ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id; |
| 2261 | ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id; |
| 2262 | ic.parm.dss1_io.proc = pc->prot.dss1.proc; |
| 2263 | ic.parm.dss1_io.timeout = -1; |
| 2264 | ic.parm.dss1_io.datalen = 0; |
| 2265 | ic.parm.dss1_io.data = NULL; |
| 2266 | free_invoke_id(pc->st, pc->prot.dss1.invoke_id); |
| 2267 | pc->prot.dss1.invoke_id = 0; /* reset id */ |
| 2268 | |
| 2269 | cs->iif.statcallb(&ic); |
| 2270 | |
| 2271 | dss1_release_l3_process(pc); |
| 2272 | } /* l3dss1_io_timer */ |
| 2273 | |
| 2274 | static void |
| 2275 | l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg) |
| 2276 | { |
| 2277 | u_char *p; |
| 2278 | struct sk_buff *skb = arg; |
| 2279 | int callState = 0; |
| 2280 | p = skb->data; |
| 2281 | |
| 2282 | if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) { |
| 2283 | p++; |
| 2284 | if (1 == *p++) |
| 2285 | callState = *p; |
| 2286 | } |
| 2287 | if (callState == 0) { |
| 2288 | /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1 |
| 2289 | * set down layer 3 without sending any message |
| 2290 | */ |
| 2291 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 2292 | newl3state(pc, 0); |
| 2293 | dss1_release_l3_process(pc); |
| 2294 | } else { |
| 2295 | pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc); |
| 2296 | } |
| 2297 | } |
| 2298 | |
| 2299 | static void |
| 2300 | l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg) |
| 2301 | { |
| 2302 | } |
| 2303 | |
| 2304 | static void |
| 2305 | l3dss1_t302(struct l3_process *pc, u_char pr, void *arg) |
| 2306 | { |
| 2307 | L3DelTimer(&pc->timer); |
| 2308 | pc->para.loc = 0; |
| 2309 | pc->para.cause = 28; /* invalid number */ |
| 2310 | l3dss1_disconnect_req(pc, pr, NULL); |
| 2311 | pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc); |
| 2312 | } |
| 2313 | |
| 2314 | static void |
| 2315 | l3dss1_t303(struct l3_process *pc, u_char pr, void *arg) |
| 2316 | { |
| 2317 | if (pc->N303 > 0) { |
| 2318 | pc->N303--; |
| 2319 | L3DelTimer(&pc->timer); |
| 2320 | l3dss1_setup_req(pc, pr, arg); |
| 2321 | } else { |
| 2322 | L3DelTimer(&pc->timer); |
| 2323 | l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102); |
| 2324 | pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc); |
| 2325 | dss1_release_l3_process(pc); |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | static void |
| 2330 | l3dss1_t304(struct l3_process *pc, u_char pr, void *arg) |
| 2331 | { |
| 2332 | L3DelTimer(&pc->timer); |
| 2333 | pc->para.loc = 0; |
| 2334 | pc->para.cause = 102; |
| 2335 | l3dss1_disconnect_req(pc, pr, NULL); |
| 2336 | pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc); |
| 2337 | |
| 2338 | } |
| 2339 | |
| 2340 | static void |
| 2341 | l3dss1_t305(struct l3_process *pc, u_char pr, void *arg) |
| 2342 | { |
| 2343 | u_char tmp[16]; |
| 2344 | u_char *p = tmp; |
| 2345 | int l; |
| 2346 | struct sk_buff *skb; |
| 2347 | u_char cause = 16; |
| 2348 | |
| 2349 | L3DelTimer(&pc->timer); |
| 2350 | if (pc->para.cause != NO_CAUSE) |
| 2351 | cause = pc->para.cause; |
| 2352 | |
| 2353 | MsgHead(p, pc->callref, MT_RELEASE); |
| 2354 | |
| 2355 | *p++ = IE_CAUSE; |
| 2356 | *p++ = 0x2; |
| 2357 | *p++ = 0x80; |
| 2358 | *p++ = cause | 0x80; |
| 2359 | |
| 2360 | l = p - tmp; |
| 2361 | if (!(skb = l3_alloc_skb(l))) |
| 2362 | return; |
| 2363 | skb_put_data(skb, tmp, l); |
| 2364 | newl3state(pc, 19); |
| 2365 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 2366 | L3AddTimer(&pc->timer, T308, CC_T308_1); |
| 2367 | } |
| 2368 | |
| 2369 | static void |
| 2370 | l3dss1_t310(struct l3_process *pc, u_char pr, void *arg) |
| 2371 | { |
| 2372 | L3DelTimer(&pc->timer); |
| 2373 | pc->para.loc = 0; |
| 2374 | pc->para.cause = 102; |
| 2375 | l3dss1_disconnect_req(pc, pr, NULL); |
| 2376 | pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc); |
| 2377 | } |
| 2378 | |
| 2379 | static void |
| 2380 | l3dss1_t313(struct l3_process *pc, u_char pr, void *arg) |
| 2381 | { |
| 2382 | L3DelTimer(&pc->timer); |
| 2383 | pc->para.loc = 0; |
| 2384 | pc->para.cause = 102; |
| 2385 | l3dss1_disconnect_req(pc, pr, NULL); |
| 2386 | pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc); |
| 2387 | } |
| 2388 | |
| 2389 | static void |
| 2390 | l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg) |
| 2391 | { |
| 2392 | newl3state(pc, 19); |
| 2393 | L3DelTimer(&pc->timer); |
| 2394 | l3dss1_message(pc, MT_RELEASE); |
| 2395 | L3AddTimer(&pc->timer, T308, CC_T308_2); |
| 2396 | } |
| 2397 | |
| 2398 | static void |
| 2399 | l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg) |
| 2400 | { |
| 2401 | L3DelTimer(&pc->timer); |
| 2402 | pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc); |
| 2403 | dss1_release_l3_process(pc); |
| 2404 | } |
| 2405 | |
| 2406 | static void |
| 2407 | l3dss1_t318(struct l3_process *pc, u_char pr, void *arg) |
| 2408 | { |
| 2409 | L3DelTimer(&pc->timer); |
| 2410 | pc->para.cause = 102; /* Timer expiry */ |
| 2411 | pc->para.loc = 0; /* local */ |
| 2412 | pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc); |
| 2413 | newl3state(pc, 19); |
| 2414 | l3dss1_message(pc, MT_RELEASE); |
| 2415 | L3AddTimer(&pc->timer, T308, CC_T308_1); |
| 2416 | } |
| 2417 | |
| 2418 | static void |
| 2419 | l3dss1_t319(struct l3_process *pc, u_char pr, void *arg) |
| 2420 | { |
| 2421 | L3DelTimer(&pc->timer); |
| 2422 | pc->para.cause = 102; /* Timer expiry */ |
| 2423 | pc->para.loc = 0; /* local */ |
| 2424 | pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc); |
| 2425 | newl3state(pc, 10); |
| 2426 | } |
| 2427 | |
| 2428 | static void |
| 2429 | l3dss1_restart(struct l3_process *pc, u_char pr, void *arg) |
| 2430 | { |
| 2431 | L3DelTimer(&pc->timer); |
| 2432 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 2433 | dss1_release_l3_process(pc); |
| 2434 | } |
| 2435 | |
| 2436 | static void |
| 2437 | l3dss1_status(struct l3_process *pc, u_char pr, void *arg) |
| 2438 | { |
| 2439 | u_char *p; |
| 2440 | struct sk_buff *skb = arg; |
| 2441 | int ret; |
| 2442 | u_char cause = 0, callState = 0; |
| 2443 | |
| 2444 | if ((ret = l3dss1_get_cause(pc, skb))) { |
| 2445 | if (pc->debug & L3_DEB_WARN) |
| 2446 | l3_debug(pc->st, "STATUS get_cause ret(%d)", ret); |
| 2447 | if (ret < 0) |
| 2448 | cause = 96; |
| 2449 | else if (ret > 0) |
| 2450 | cause = 100; |
| 2451 | } |
| 2452 | if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) { |
| 2453 | p++; |
| 2454 | if (1 == *p++) { |
| 2455 | callState = *p; |
| 2456 | if (!ie_in_set(pc, *p, l3_valid_states)) |
| 2457 | cause = 100; |
| 2458 | } else |
| 2459 | cause = 100; |
| 2460 | } else |
| 2461 | cause = 96; |
| 2462 | if (!cause) { /* no error before */ |
| 2463 | ret = check_infoelements(pc, skb, ie_STATUS); |
| 2464 | if (ERR_IE_COMPREHENSION == ret) |
| 2465 | cause = 96; |
| 2466 | else if (ERR_IE_UNRECOGNIZED == ret) |
| 2467 | cause = 99; |
| 2468 | } |
| 2469 | if (cause) { |
| 2470 | u_char tmp; |
| 2471 | |
| 2472 | if (pc->debug & L3_DEB_WARN) |
| 2473 | l3_debug(pc->st, "STATUS error(%d/%d)", ret, cause); |
| 2474 | tmp = pc->para.cause; |
| 2475 | pc->para.cause = cause; |
| 2476 | l3dss1_status_send(pc, 0, NULL); |
| 2477 | if (cause == 99) |
| 2478 | pc->para.cause = tmp; |
| 2479 | else |
| 2480 | return; |
| 2481 | } |
| 2482 | cause = pc->para.cause; |
| 2483 | if (((cause & 0x7f) == 111) && (callState == 0)) { |
| 2484 | /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... |
| 2485 | * if received MT_STATUS with cause == 111 and call |
| 2486 | * state == 0, then we must set down layer 3 |
| 2487 | */ |
| 2488 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 2489 | newl3state(pc, 0); |
| 2490 | dss1_release_l3_process(pc); |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | static void |
| 2495 | l3dss1_facility(struct l3_process *pc, u_char pr, void *arg) |
| 2496 | { |
| 2497 | struct sk_buff *skb = arg; |
| 2498 | int ret; |
| 2499 | |
| 2500 | ret = check_infoelements(pc, skb, ie_FACILITY); |
| 2501 | l3dss1_std_ie_err(pc, ret); |
| 2502 | { |
| 2503 | u_char *p; |
| 2504 | if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) |
| 2505 | l3dss1_parse_facility(pc->st, pc, pc->callref, p); |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | static void |
| 2510 | l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg) |
| 2511 | { |
| 2512 | struct sk_buff *skb; |
| 2513 | u_char tmp[32]; |
| 2514 | u_char *p = tmp; |
| 2515 | u_char i, l; |
| 2516 | u_char *msg = pc->chan->setup.phone; |
| 2517 | |
| 2518 | MsgHead(p, pc->callref, MT_SUSPEND); |
| 2519 | l = *msg++; |
| 2520 | if (l && (l <= 10)) { /* Max length 10 octets */ |
| 2521 | *p++ = IE_CALL_ID; |
| 2522 | *p++ = l; |
| 2523 | for (i = 0; i < l; i++) |
| 2524 | *p++ = *msg++; |
| 2525 | } else if (l) { |
| 2526 | l3_debug(pc->st, "SUS wrong CALL_ID len %d", l); |
| 2527 | return; |
| 2528 | } |
| 2529 | l = p - tmp; |
| 2530 | if (!(skb = l3_alloc_skb(l))) |
| 2531 | return; |
| 2532 | skb_put_data(skb, tmp, l); |
| 2533 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 2534 | newl3state(pc, 15); |
| 2535 | L3AddTimer(&pc->timer, T319, CC_T319); |
| 2536 | } |
| 2537 | |
| 2538 | static void |
| 2539 | l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg) |
| 2540 | { |
| 2541 | struct sk_buff *skb = arg; |
| 2542 | int ret; |
| 2543 | |
| 2544 | L3DelTimer(&pc->timer); |
| 2545 | newl3state(pc, 0); |
| 2546 | pc->para.cause = NO_CAUSE; |
| 2547 | pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc); |
| 2548 | /* We don't handle suspend_ack for IE errors now */ |
| 2549 | if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE))) |
| 2550 | if (pc->debug & L3_DEB_WARN) |
| 2551 | l3_debug(pc->st, "SUSPACK check ie(%d)", ret); |
| 2552 | dss1_release_l3_process(pc); |
| 2553 | } |
| 2554 | |
| 2555 | static void |
| 2556 | l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg) |
| 2557 | { |
| 2558 | struct sk_buff *skb = arg; |
| 2559 | int ret; |
| 2560 | |
| 2561 | if ((ret = l3dss1_get_cause(pc, skb))) { |
| 2562 | if (pc->debug & L3_DEB_WARN) |
| 2563 | l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)", ret); |
| 2564 | if (ret < 0) |
| 2565 | pc->para.cause = 96; |
| 2566 | else |
| 2567 | pc->para.cause = 100; |
| 2568 | l3dss1_status_send(pc, pr, NULL); |
| 2569 | return; |
| 2570 | } |
| 2571 | ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT); |
| 2572 | if (ERR_IE_COMPREHENSION == ret) { |
| 2573 | l3dss1_std_ie_err(pc, ret); |
| 2574 | return; |
| 2575 | } |
| 2576 | L3DelTimer(&pc->timer); |
| 2577 | pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc); |
| 2578 | newl3state(pc, 10); |
| 2579 | if (ret) /* STATUS for none mandatory IE errors after actions are taken */ |
| 2580 | l3dss1_std_ie_err(pc, ret); |
| 2581 | } |
| 2582 | |
| 2583 | static void |
| 2584 | l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg) |
| 2585 | { |
| 2586 | struct sk_buff *skb; |
| 2587 | u_char tmp[32]; |
| 2588 | u_char *p = tmp; |
| 2589 | u_char i, l; |
| 2590 | u_char *msg = pc->para.setup.phone; |
| 2591 | |
| 2592 | MsgHead(p, pc->callref, MT_RESUME); |
| 2593 | |
| 2594 | l = *msg++; |
| 2595 | if (l && (l <= 10)) { /* Max length 10 octets */ |
| 2596 | *p++ = IE_CALL_ID; |
| 2597 | *p++ = l; |
| 2598 | for (i = 0; i < l; i++) |
| 2599 | *p++ = *msg++; |
| 2600 | } else if (l) { |
| 2601 | l3_debug(pc->st, "RES wrong CALL_ID len %d", l); |
| 2602 | return; |
| 2603 | } |
| 2604 | l = p - tmp; |
| 2605 | if (!(skb = l3_alloc_skb(l))) |
| 2606 | return; |
| 2607 | skb_put_data(skb, tmp, l); |
| 2608 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 2609 | newl3state(pc, 17); |
| 2610 | L3AddTimer(&pc->timer, T318, CC_T318); |
| 2611 | } |
| 2612 | |
| 2613 | static void |
| 2614 | l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg) |
| 2615 | { |
| 2616 | struct sk_buff *skb = arg; |
| 2617 | int id, ret; |
| 2618 | |
| 2619 | if ((id = l3dss1_get_channel_id(pc, skb)) > 0) { |
| 2620 | if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) { |
| 2621 | if (pc->debug & L3_DEB_WARN) |
| 2622 | l3_debug(pc->st, "resume ack with wrong chid %x", id); |
| 2623 | pc->para.cause = 100; |
| 2624 | l3dss1_status_send(pc, pr, NULL); |
| 2625 | return; |
| 2626 | } |
| 2627 | pc->para.bchannel = id; |
| 2628 | } else if (1 == pc->state) { |
| 2629 | if (pc->debug & L3_DEB_WARN) |
| 2630 | l3_debug(pc->st, "resume ack without chid (ret %d)", id); |
| 2631 | pc->para.cause = 96; |
| 2632 | l3dss1_status_send(pc, pr, NULL); |
| 2633 | return; |
| 2634 | } |
| 2635 | ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE); |
| 2636 | if (ERR_IE_COMPREHENSION == ret) { |
| 2637 | l3dss1_std_ie_err(pc, ret); |
| 2638 | return; |
| 2639 | } |
| 2640 | L3DelTimer(&pc->timer); |
| 2641 | pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc); |
| 2642 | newl3state(pc, 10); |
| 2643 | if (ret) /* STATUS for none mandatory IE errors after actions are taken */ |
| 2644 | l3dss1_std_ie_err(pc, ret); |
| 2645 | } |
| 2646 | |
| 2647 | static void |
| 2648 | l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg) |
| 2649 | { |
| 2650 | struct sk_buff *skb = arg; |
| 2651 | int ret; |
| 2652 | |
| 2653 | if ((ret = l3dss1_get_cause(pc, skb))) { |
| 2654 | if (pc->debug & L3_DEB_WARN) |
| 2655 | l3_debug(pc->st, "RES_REJ get_cause ret(%d)", ret); |
| 2656 | if (ret < 0) |
| 2657 | pc->para.cause = 96; |
| 2658 | else |
| 2659 | pc->para.cause = 100; |
| 2660 | l3dss1_status_send(pc, pr, NULL); |
| 2661 | return; |
| 2662 | } |
| 2663 | ret = check_infoelements(pc, skb, ie_RESUME_REJECT); |
| 2664 | if (ERR_IE_COMPREHENSION == ret) { |
| 2665 | l3dss1_std_ie_err(pc, ret); |
| 2666 | return; |
| 2667 | } |
| 2668 | L3DelTimer(&pc->timer); |
| 2669 | pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc); |
| 2670 | newl3state(pc, 0); |
| 2671 | if (ret) /* STATUS for none mandatory IE errors after actions are taken */ |
| 2672 | l3dss1_std_ie_err(pc, ret); |
| 2673 | dss1_release_l3_process(pc); |
| 2674 | } |
| 2675 | |
| 2676 | static void |
| 2677 | l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg) |
| 2678 | { |
| 2679 | u_char tmp[32]; |
| 2680 | u_char *p; |
| 2681 | u_char ri, ch = 0, chan = 0; |
| 2682 | int l; |
| 2683 | struct sk_buff *skb = arg; |
| 2684 | struct l3_process *up; |
| 2685 | |
| 2686 | newl3state(pc, 2); |
| 2687 | L3DelTimer(&pc->timer); |
| 2688 | p = skb->data; |
| 2689 | if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) { |
| 2690 | ri = p[2]; |
| 2691 | l3_debug(pc->st, "Restart %x", ri); |
| 2692 | } else { |
| 2693 | l3_debug(pc->st, "Restart without restart IE"); |
| 2694 | ri = 0x86; |
| 2695 | } |
| 2696 | p = skb->data; |
| 2697 | if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) { |
| 2698 | chan = p[2] & 3; |
| 2699 | ch = p[2]; |
| 2700 | if (pc->st->l3.debug) |
| 2701 | l3_debug(pc->st, "Restart for channel %d", chan); |
| 2702 | } |
| 2703 | newl3state(pc, 2); |
| 2704 | up = pc->st->l3.proc; |
| 2705 | while (up) { |
| 2706 | if ((ri & 7) == 7) |
| 2707 | up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up); |
| 2708 | else if (up->para.bchannel == chan) |
| 2709 | up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up); |
| 2710 | up = up->next; |
| 2711 | } |
| 2712 | p = tmp; |
| 2713 | MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE); |
| 2714 | if (chan) { |
| 2715 | *p++ = IE_CHANNEL_ID; |
| 2716 | *p++ = 1; |
| 2717 | *p++ = ch | 0x80; |
| 2718 | } |
| 2719 | *p++ = 0x79; /* RESTART Ind */ |
| 2720 | *p++ = 1; |
| 2721 | *p++ = ri; |
| 2722 | l = p - tmp; |
| 2723 | if (!(skb = l3_alloc_skb(l))) |
| 2724 | return; |
| 2725 | skb_put_data(skb, tmp, l); |
| 2726 | newl3state(pc, 0); |
| 2727 | l3_msg(pc->st, DL_DATA | REQUEST, skb); |
| 2728 | } |
| 2729 | |
| 2730 | static void |
| 2731 | l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg) |
| 2732 | { |
| 2733 | pc->para.cause = 0x29; /* Temporary failure */ |
| 2734 | pc->para.loc = 0; |
| 2735 | l3dss1_disconnect_req(pc, pr, NULL); |
| 2736 | pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc); |
| 2737 | } |
| 2738 | |
| 2739 | static void |
| 2740 | l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg) |
| 2741 | { |
| 2742 | newl3state(pc, 0); |
| 2743 | pc->para.cause = 0x1b; /* Destination out of order */ |
| 2744 | pc->para.loc = 0; |
| 2745 | pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc); |
| 2746 | release_l3_process(pc); |
| 2747 | } |
| 2748 | |
| 2749 | static void |
| 2750 | l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg) |
| 2751 | { |
| 2752 | L3DelTimer(&pc->timer); |
| 2753 | L3AddTimer(&pc->timer, T309, CC_T309); |
| 2754 | l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL); |
| 2755 | } |
| 2756 | |
| 2757 | static void |
| 2758 | l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg) |
| 2759 | { |
| 2760 | L3DelTimer(&pc->timer); |
| 2761 | |
| 2762 | pc->para.cause = 0x1F; /* normal, unspecified */ |
| 2763 | l3dss1_status_send(pc, 0, NULL); |
| 2764 | } |
| 2765 | |
| 2766 | /* *INDENT-OFF* */ |
| 2767 | static struct stateentry downstatelist[] = |
| 2768 | { |
| 2769 | {SBIT(0), |
| 2770 | CC_SETUP | REQUEST, l3dss1_setup_req}, |
| 2771 | {SBIT(0), |
| 2772 | CC_RESUME | REQUEST, l3dss1_resume_req}, |
| 2773 | {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25), |
| 2774 | CC_DISCONNECT | REQUEST, l3dss1_disconnect_req}, |
| 2775 | {SBIT(12), |
| 2776 | CC_RELEASE | REQUEST, l3dss1_release_req}, |
| 2777 | {ALL_STATES, |
| 2778 | CC_RESTART | REQUEST, l3dss1_restart}, |
| 2779 | {SBIT(6) | SBIT(25), |
| 2780 | CC_IGNORE | REQUEST, l3dss1_reset}, |
| 2781 | {SBIT(6) | SBIT(25), |
| 2782 | CC_REJECT | REQUEST, l3dss1_reject_req}, |
| 2783 | {SBIT(6) | SBIT(25), |
| 2784 | CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req}, |
| 2785 | {SBIT(6), |
| 2786 | CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req}, |
| 2787 | {SBIT(25), |
| 2788 | CC_MORE_INFO | REQUEST, l3dss1_dummy}, |
| 2789 | {SBIT(6) | SBIT(9) | SBIT(25), |
| 2790 | CC_ALERTING | REQUEST, l3dss1_alert_req}, |
| 2791 | {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25), |
| 2792 | CC_SETUP | RESPONSE, l3dss1_setup_rsp}, |
| 2793 | {SBIT(10), |
| 2794 | CC_SUSPEND | REQUEST, l3dss1_suspend_req}, |
| 2795 | {SBIT(7) | SBIT(9) | SBIT(25), |
| 2796 | CC_REDIR | REQUEST, l3dss1_redir_req}, |
| 2797 | {SBIT(6), |
| 2798 | CC_REDIR | REQUEST, l3dss1_redir_req_early}, |
| 2799 | {SBIT(9) | SBIT(25), |
| 2800 | CC_DISCONNECT | REQUEST, l3dss1_disconnect_req}, |
| 2801 | {SBIT(25), |
| 2802 | CC_T302, l3dss1_t302}, |
| 2803 | {SBIT(1), |
| 2804 | CC_T303, l3dss1_t303}, |
| 2805 | {SBIT(2), |
| 2806 | CC_T304, l3dss1_t304}, |
| 2807 | {SBIT(3), |
| 2808 | CC_T310, l3dss1_t310}, |
| 2809 | {SBIT(8), |
| 2810 | CC_T313, l3dss1_t313}, |
| 2811 | {SBIT(11), |
| 2812 | CC_T305, l3dss1_t305}, |
| 2813 | {SBIT(15), |
| 2814 | CC_T319, l3dss1_t319}, |
| 2815 | {SBIT(17), |
| 2816 | CC_T318, l3dss1_t318}, |
| 2817 | {SBIT(19), |
| 2818 | CC_T308_1, l3dss1_t308_1}, |
| 2819 | {SBIT(19), |
| 2820 | CC_T308_2, l3dss1_t308_2}, |
| 2821 | {SBIT(10), |
| 2822 | CC_T309, l3dss1_dl_release}, |
| 2823 | }; |
| 2824 | |
| 2825 | static struct stateentry datastatelist[] = |
| 2826 | { |
| 2827 | {ALL_STATES, |
| 2828 | MT_STATUS_ENQUIRY, l3dss1_status_enq}, |
| 2829 | {ALL_STATES, |
| 2830 | MT_FACILITY, l3dss1_facility}, |
| 2831 | {SBIT(19), |
| 2832 | MT_STATUS, l3dss1_release_ind}, |
| 2833 | {ALL_STATES, |
| 2834 | MT_STATUS, l3dss1_status}, |
| 2835 | {SBIT(0), |
| 2836 | MT_SETUP, l3dss1_setup}, |
| 2837 | {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) | |
| 2838 | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25), |
| 2839 | MT_SETUP, l3dss1_dummy}, |
| 2840 | {SBIT(1) | SBIT(2), |
| 2841 | MT_CALL_PROCEEDING, l3dss1_call_proc}, |
| 2842 | {SBIT(1), |
| 2843 | MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack}, |
| 2844 | {SBIT(2) | SBIT(3), |
| 2845 | MT_ALERTING, l3dss1_alerting}, |
| 2846 | {SBIT(2) | SBIT(3), |
| 2847 | MT_PROGRESS, l3dss1_progress}, |
| 2848 | {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | |
| 2849 | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25), |
| 2850 | MT_INFORMATION, l3dss1_information}, |
| 2851 | {SBIT(10) | SBIT(11) | SBIT(15), |
| 2852 | MT_NOTIFY, l3dss1_notify}, |
| 2853 | {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) | |
| 2854 | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25), |
| 2855 | MT_RELEASE_COMPLETE, l3dss1_release_cmpl}, |
| 2856 | {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), |
| 2857 | MT_RELEASE, l3dss1_release}, |
| 2858 | {SBIT(19), MT_RELEASE, l3dss1_release_ind}, |
| 2859 | {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25), |
| 2860 | MT_DISCONNECT, l3dss1_disconnect}, |
| 2861 | {SBIT(19), |
| 2862 | MT_DISCONNECT, l3dss1_dummy}, |
| 2863 | {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4), |
| 2864 | MT_CONNECT, l3dss1_connect}, |
| 2865 | {SBIT(8), |
| 2866 | MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack}, |
| 2867 | {SBIT(15), |
| 2868 | MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack}, |
| 2869 | {SBIT(15), |
| 2870 | MT_SUSPEND_REJECT, l3dss1_suspend_rej}, |
| 2871 | {SBIT(17), |
| 2872 | MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack}, |
| 2873 | {SBIT(17), |
| 2874 | MT_RESUME_REJECT, l3dss1_resume_rej}, |
| 2875 | }; |
| 2876 | |
| 2877 | static struct stateentry globalmes_list[] = |
| 2878 | { |
| 2879 | {ALL_STATES, |
| 2880 | MT_STATUS, l3dss1_status}, |
| 2881 | {SBIT(0), |
| 2882 | MT_RESTART, l3dss1_global_restart}, |
| 2883 | /* {SBIT(1), |
| 2884 | MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack}, |
| 2885 | */ |
| 2886 | }; |
| 2887 | |
| 2888 | static struct stateentry manstatelist[] = |
| 2889 | { |
| 2890 | {SBIT(2), |
| 2891 | DL_ESTABLISH | INDICATION, l3dss1_dl_reset}, |
| 2892 | {SBIT(10), |
| 2893 | DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status}, |
| 2894 | {SBIT(10), |
| 2895 | DL_RELEASE | INDICATION, l3dss1_dl_reestablish}, |
| 2896 | {ALL_STATES, |
| 2897 | DL_RELEASE | INDICATION, l3dss1_dl_release}, |
| 2898 | }; |
| 2899 | |
| 2900 | /* *INDENT-ON* */ |
| 2901 | |
| 2902 | |
| 2903 | static void |
| 2904 | global_handler(struct PStack *st, int mt, struct sk_buff *skb) |
| 2905 | { |
| 2906 | u_char tmp[16]; |
| 2907 | u_char *p = tmp; |
| 2908 | int l; |
| 2909 | int i; |
| 2910 | struct l3_process *proc = st->l3.global; |
| 2911 | |
| 2912 | proc->callref = skb->data[2]; /* cr flag */ |
| 2913 | for (i = 0; i < ARRAY_SIZE(globalmes_list); i++) |
| 2914 | if ((mt == globalmes_list[i].primitive) && |
| 2915 | ((1 << proc->state) & globalmes_list[i].state)) |
| 2916 | break; |
| 2917 | if (i == ARRAY_SIZE(globalmes_list)) { |
| 2918 | if (st->l3.debug & L3_DEB_STATE) { |
| 2919 | l3_debug(st, "dss1 global state %d mt %x unhandled", |
| 2920 | proc->state, mt); |
| 2921 | } |
| 2922 | MsgHead(p, proc->callref, MT_STATUS); |
| 2923 | *p++ = IE_CAUSE; |
| 2924 | *p++ = 0x2; |
| 2925 | *p++ = 0x80; |
| 2926 | *p++ = 81 | 0x80; /* invalid cr */ |
| 2927 | *p++ = 0x14; /* CallState */ |
| 2928 | *p++ = 0x1; |
| 2929 | *p++ = proc->state & 0x3f; |
| 2930 | l = p - tmp; |
| 2931 | if (!(skb = l3_alloc_skb(l))) |
| 2932 | return; |
| 2933 | skb_put_data(skb, tmp, l); |
| 2934 | l3_msg(proc->st, DL_DATA | REQUEST, skb); |
| 2935 | } else { |
| 2936 | if (st->l3.debug & L3_DEB_STATE) { |
| 2937 | l3_debug(st, "dss1 global %d mt %x", |
| 2938 | proc->state, mt); |
| 2939 | } |
| 2940 | globalmes_list[i].rout(proc, mt, skb); |
| 2941 | } |
| 2942 | } |
| 2943 | |
| 2944 | static void |
| 2945 | dss1up(struct PStack *st, int pr, void *arg) |
| 2946 | { |
| 2947 | int i, mt, cr, callState; |
| 2948 | char *ptr; |
| 2949 | u_char *p; |
| 2950 | struct sk_buff *skb = arg; |
| 2951 | struct l3_process *proc; |
| 2952 | |
| 2953 | switch (pr) { |
| 2954 | case (DL_DATA | INDICATION): |
| 2955 | case (DL_UNIT_DATA | INDICATION): |
| 2956 | break; |
| 2957 | case (DL_ESTABLISH | CONFIRM): |
| 2958 | case (DL_ESTABLISH | INDICATION): |
| 2959 | case (DL_RELEASE | INDICATION): |
| 2960 | case (DL_RELEASE | CONFIRM): |
| 2961 | l3_msg(st, pr, arg); |
| 2962 | return; |
| 2963 | break; |
| 2964 | default: |
| 2965 | printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr); |
| 2966 | return; |
| 2967 | } |
| 2968 | if (skb->len < 3) { |
| 2969 | l3_debug(st, "dss1up frame too short(%d)", skb->len); |
| 2970 | dev_kfree_skb(skb); |
| 2971 | return; |
| 2972 | } |
| 2973 | |
| 2974 | if (skb->data[0] != PROTO_DIS_EURO) { |
| 2975 | if (st->l3.debug & L3_DEB_PROTERR) { |
| 2976 | l3_debug(st, "dss1up%sunexpected discriminator %x message len %d", |
| 2977 | (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", |
| 2978 | skb->data[0], skb->len); |
| 2979 | } |
| 2980 | dev_kfree_skb(skb); |
| 2981 | return; |
| 2982 | } |
| 2983 | cr = getcallref(skb->data); |
| 2984 | if (skb->len < ((skb->data[1] & 0x0f) + 3)) { |
| 2985 | l3_debug(st, "dss1up frame too short(%d)", skb->len); |
| 2986 | dev_kfree_skb(skb); |
| 2987 | return; |
| 2988 | } |
| 2989 | mt = skb->data[skb->data[1] + 2]; |
| 2990 | if (st->l3.debug & L3_DEB_STATE) |
| 2991 | l3_debug(st, "dss1up cr %d", cr); |
| 2992 | if (cr == -2) { /* wrong Callref */ |
| 2993 | if (st->l3.debug & L3_DEB_WARN) |
| 2994 | l3_debug(st, "dss1up wrong Callref"); |
| 2995 | dev_kfree_skb(skb); |
| 2996 | return; |
| 2997 | } else if (cr == -1) { /* Dummy Callref */ |
| 2998 | if (mt == MT_FACILITY) |
| 2999 | if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) { |
| 3000 | l3dss1_parse_facility(st, NULL, |
| 3001 | (pr == (DL_DATA | INDICATION)) ? -1 : -2, p); |
| 3002 | dev_kfree_skb(skb); |
| 3003 | return; |
| 3004 | } |
| 3005 | if (st->l3.debug & L3_DEB_WARN) |
| 3006 | l3_debug(st, "dss1up dummy Callref (no facility msg or ie)"); |
| 3007 | dev_kfree_skb(skb); |
| 3008 | return; |
| 3009 | } else if ((((skb->data[1] & 0x0f) == 1) && (0 == (cr & 0x7f))) || |
| 3010 | (((skb->data[1] & 0x0f) == 2) && (0 == (cr & 0x7fff)))) { /* Global CallRef */ |
| 3011 | if (st->l3.debug & L3_DEB_STATE) |
| 3012 | l3_debug(st, "dss1up Global CallRef"); |
| 3013 | global_handler(st, mt, skb); |
| 3014 | dev_kfree_skb(skb); |
| 3015 | return; |
| 3016 | } else if (!(proc = getl3proc(st, cr))) { |
| 3017 | /* No transaction process exist, that means no call with |
| 3018 | * this callreference is active |
| 3019 | */ |
| 3020 | if (mt == MT_SETUP) { |
| 3021 | /* Setup creates a new transaction process */ |
| 3022 | if (skb->data[2] & 0x80) { |
| 3023 | /* Setup with wrong CREF flag */ |
| 3024 | if (st->l3.debug & L3_DEB_STATE) |
| 3025 | l3_debug(st, "dss1up wrong CRef flag"); |
| 3026 | dev_kfree_skb(skb); |
| 3027 | return; |
| 3028 | } |
| 3029 | if (!(proc = dss1_new_l3_process(st, cr))) { |
| 3030 | /* May be to answer with RELEASE_COMPLETE and |
| 3031 | * CAUSE 0x2f "Resource unavailable", but this |
| 3032 | * need a new_l3_process too ... arghh |
| 3033 | */ |
| 3034 | dev_kfree_skb(skb); |
| 3035 | return; |
| 3036 | } |
| 3037 | } else if (mt == MT_STATUS) { |
| 3038 | if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) { |
| 3039 | ptr++; |
| 3040 | if (*ptr++ == 2) |
| 3041 | ptr++; |
| 3042 | } |
| 3043 | callState = 0; |
| 3044 | if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) { |
| 3045 | ptr++; |
| 3046 | if (*ptr++ == 2) |
| 3047 | ptr++; |
| 3048 | callState = *ptr; |
| 3049 | } |
| 3050 | /* ETS 300-104 part 2.4.1 |
| 3051 | * if setup has not been made and a message type |
| 3052 | * MT_STATUS is received with call state == 0, |
| 3053 | * we must send nothing |
| 3054 | */ |
| 3055 | if (callState != 0) { |
| 3056 | /* ETS 300-104 part 2.4.2 |
| 3057 | * if setup has not been made and a message type |
| 3058 | * MT_STATUS is received with call state != 0, |
| 3059 | * we must send MT_RELEASE_COMPLETE cause 101 |
| 3060 | */ |
| 3061 | if ((proc = dss1_new_l3_process(st, cr))) { |
| 3062 | proc->para.cause = 101; |
| 3063 | l3dss1_msg_without_setup(proc, 0, NULL); |
| 3064 | } |
| 3065 | } |
| 3066 | dev_kfree_skb(skb); |
| 3067 | return; |
| 3068 | } else if (mt == MT_RELEASE_COMPLETE) { |
| 3069 | dev_kfree_skb(skb); |
| 3070 | return; |
| 3071 | } else { |
| 3072 | /* ETS 300-104 part 2 |
| 3073 | * if setup has not been made and a message type |
| 3074 | * (except MT_SETUP and RELEASE_COMPLETE) is received, |
| 3075 | * we must send MT_RELEASE_COMPLETE cause 81 */ |
| 3076 | dev_kfree_skb(skb); |
| 3077 | if ((proc = dss1_new_l3_process(st, cr))) { |
| 3078 | proc->para.cause = 81; |
| 3079 | l3dss1_msg_without_setup(proc, 0, NULL); |
| 3080 | } |
| 3081 | return; |
| 3082 | } |
| 3083 | } |
| 3084 | if (l3dss1_check_messagetype_validity(proc, mt, skb)) { |
| 3085 | dev_kfree_skb(skb); |
| 3086 | return; |
| 3087 | } |
| 3088 | if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL) |
| 3089 | l3dss1_deliver_display(proc, pr, p); /* Display IE included */ |
| 3090 | for (i = 0; i < ARRAY_SIZE(datastatelist); i++) |
| 3091 | if ((mt == datastatelist[i].primitive) && |
| 3092 | ((1 << proc->state) & datastatelist[i].state)) |
| 3093 | break; |
| 3094 | if (i == ARRAY_SIZE(datastatelist)) { |
| 3095 | if (st->l3.debug & L3_DEB_STATE) { |
| 3096 | l3_debug(st, "dss1up%sstate %d mt %#x unhandled", |
| 3097 | (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", |
| 3098 | proc->state, mt); |
| 3099 | } |
| 3100 | if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) { |
| 3101 | proc->para.cause = 101; |
| 3102 | l3dss1_status_send(proc, pr, skb); |
| 3103 | } |
| 3104 | } else { |
| 3105 | if (st->l3.debug & L3_DEB_STATE) { |
| 3106 | l3_debug(st, "dss1up%sstate %d mt %x", |
| 3107 | (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", |
| 3108 | proc->state, mt); |
| 3109 | } |
| 3110 | datastatelist[i].rout(proc, pr, skb); |
| 3111 | } |
| 3112 | dev_kfree_skb(skb); |
| 3113 | return; |
| 3114 | } |
| 3115 | |
| 3116 | static void |
| 3117 | dss1down(struct PStack *st, int pr, void *arg) |
| 3118 | { |
| 3119 | int i, cr; |
| 3120 | struct l3_process *proc; |
| 3121 | struct Channel *chan; |
| 3122 | |
| 3123 | if ((DL_ESTABLISH | REQUEST) == pr) { |
| 3124 | l3_msg(st, pr, NULL); |
| 3125 | return; |
| 3126 | } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) { |
| 3127 | chan = arg; |
| 3128 | cr = newcallref(); |
| 3129 | cr |= 0x80; |
| 3130 | if ((proc = dss1_new_l3_process(st, cr))) { |
| 3131 | proc->chan = chan; |
| 3132 | chan->proc = proc; |
| 3133 | memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm)); |
| 3134 | proc->callref = cr; |
| 3135 | } |
| 3136 | } else { |
| 3137 | proc = arg; |
| 3138 | } |
| 3139 | if (!proc) { |
| 3140 | printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr); |
| 3141 | return; |
| 3142 | } |
| 3143 | |
| 3144 | if (pr == (CC_TDSS1_IO | REQUEST)) { |
| 3145 | l3dss1_io_timer(proc); /* timer expires */ |
| 3146 | return; |
| 3147 | } |
| 3148 | |
| 3149 | for (i = 0; i < ARRAY_SIZE(downstatelist); i++) |
| 3150 | if ((pr == downstatelist[i].primitive) && |
| 3151 | ((1 << proc->state) & downstatelist[i].state)) |
| 3152 | break; |
| 3153 | if (i == ARRAY_SIZE(downstatelist)) { |
| 3154 | if (st->l3.debug & L3_DEB_STATE) { |
| 3155 | l3_debug(st, "dss1down state %d prim %#x unhandled", |
| 3156 | proc->state, pr); |
| 3157 | } |
| 3158 | } else { |
| 3159 | if (st->l3.debug & L3_DEB_STATE) { |
| 3160 | l3_debug(st, "dss1down state %d prim %#x", |
| 3161 | proc->state, pr); |
| 3162 | } |
| 3163 | downstatelist[i].rout(proc, pr, arg); |
| 3164 | } |
| 3165 | } |
| 3166 | |
| 3167 | static void |
| 3168 | dss1man(struct PStack *st, int pr, void *arg) |
| 3169 | { |
| 3170 | int i; |
| 3171 | struct l3_process *proc = arg; |
| 3172 | |
| 3173 | if (!proc) { |
| 3174 | printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr); |
| 3175 | return; |
| 3176 | } |
| 3177 | for (i = 0; i < ARRAY_SIZE(manstatelist); i++) |
| 3178 | if ((pr == manstatelist[i].primitive) && |
| 3179 | ((1 << proc->state) & manstatelist[i].state)) |
| 3180 | break; |
| 3181 | if (i == ARRAY_SIZE(manstatelist)) { |
| 3182 | if (st->l3.debug & L3_DEB_STATE) { |
| 3183 | l3_debug(st, "cr %d dss1man state %d prim %#x unhandled", |
| 3184 | proc->callref & 0x7f, proc->state, pr); |
| 3185 | } |
| 3186 | } else { |
| 3187 | if (st->l3.debug & L3_DEB_STATE) { |
| 3188 | l3_debug(st, "cr %d dss1man state %d prim %#x", |
| 3189 | proc->callref & 0x7f, proc->state, pr); |
| 3190 | } |
| 3191 | manstatelist[i].rout(proc, pr, arg); |
| 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | void |
| 3196 | setstack_dss1(struct PStack *st) |
| 3197 | { |
| 3198 | char tmp[64]; |
| 3199 | int i; |
| 3200 | |
| 3201 | st->lli.l4l3 = dss1down; |
| 3202 | st->lli.l4l3_proto = l3dss1_cmd_global; |
| 3203 | st->l2.l2l3 = dss1up; |
| 3204 | st->l3.l3ml3 = dss1man; |
| 3205 | st->l3.N303 = 1; |
| 3206 | st->prot.dss1.last_invoke_id = 0; |
| 3207 | st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */ |
| 3208 | i = 1; |
| 3209 | while (i < 32) |
| 3210 | st->prot.dss1.invoke_used[i++] = 0; |
| 3211 | |
| 3212 | if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) { |
| 3213 | printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n"); |
| 3214 | } else { |
| 3215 | st->l3.global->state = 0; |
| 3216 | st->l3.global->callref = 0; |
| 3217 | st->l3.global->next = NULL; |
| 3218 | st->l3.global->debug = L3_DEB_WARN; |
| 3219 | st->l3.global->st = st; |
| 3220 | st->l3.global->N303 = 1; |
| 3221 | st->l3.global->prot.dss1.invoke_id = 0; |
| 3222 | |
| 3223 | L3InitTimer(st->l3.global, &st->l3.global->timer); |
| 3224 | } |
| 3225 | strcpy(tmp, dss1_revision); |
| 3226 | printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp)); |
| 3227 | } |