| .. | .. |
|---|
| 20 | 20 | #include <linux/isdn/capiutil.h> |
|---|
| 21 | 21 | #include <linux/slab.h> |
|---|
| 22 | 22 | |
|---|
| 23 | +#include "kcapi.h" |
|---|
| 24 | + |
|---|
| 23 | 25 | /* from CAPI2.0 DDK AVM Berlin GmbH */ |
|---|
| 24 | 26 | |
|---|
| 25 | 27 | typedef struct { |
|---|
| .. | .. |
|---|
| 245 | 247 | } |
|---|
| 246 | 248 | } |
|---|
| 247 | 249 | } |
|---|
| 248 | | -/*-------------------------------------------------------*/ |
|---|
| 249 | | -static void pars_2_message(_cmsg *cmsg) |
|---|
| 250 | | -{ |
|---|
| 251 | | - |
|---|
| 252 | | - for (; TYP != _CEND; cmsg->p++) { |
|---|
| 253 | | - switch (TYP) { |
|---|
| 254 | | - case _CBYTE: |
|---|
| 255 | | - byteTLcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 256 | | - cmsg->l++; |
|---|
| 257 | | - break; |
|---|
| 258 | | - case _CWORD: |
|---|
| 259 | | - wordTLcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 260 | | - cmsg->l += 2; |
|---|
| 261 | | - break; |
|---|
| 262 | | - case _CDWORD: |
|---|
| 263 | | - dwordTLcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 264 | | - cmsg->l += 4; |
|---|
| 265 | | - break; |
|---|
| 266 | | - case _CSTRUCT: |
|---|
| 267 | | - if (*(u8 **) OFF == NULL) { |
|---|
| 268 | | - *(cmsg->m + cmsg->l) = '\0'; |
|---|
| 269 | | - cmsg->l++; |
|---|
| 270 | | - } else if (**(_cstruct *) OFF != 0xff) { |
|---|
| 271 | | - structTLcpy(cmsg->m + cmsg->l, *(_cstruct *) OFF, 1 + **(_cstruct *) OFF); |
|---|
| 272 | | - cmsg->l += 1 + **(_cstruct *) OFF; |
|---|
| 273 | | - } else { |
|---|
| 274 | | - _cstruct s = *(_cstruct *) OFF; |
|---|
| 275 | | - structTLcpy(cmsg->m + cmsg->l, s, 3 + *(u16 *) (s + 1)); |
|---|
| 276 | | - cmsg->l += 3 + *(u16 *) (s + 1); |
|---|
| 277 | | - } |
|---|
| 278 | | - break; |
|---|
| 279 | | - case _CMSTRUCT: |
|---|
| 280 | | -/*----- Metastruktur 0 -----*/ |
|---|
| 281 | | - if (*(_cmstruct *) OFF == CAPI_DEFAULT) { |
|---|
| 282 | | - *(cmsg->m + cmsg->l) = '\0'; |
|---|
| 283 | | - cmsg->l++; |
|---|
| 284 | | - jumpcstruct(cmsg); |
|---|
| 285 | | - } |
|---|
| 286 | | -/*----- Metastruktur wird composed -----*/ |
|---|
| 287 | | - else { |
|---|
| 288 | | - unsigned _l = cmsg->l; |
|---|
| 289 | | - unsigned _ls; |
|---|
| 290 | | - cmsg->l++; |
|---|
| 291 | | - cmsg->p++; |
|---|
| 292 | | - pars_2_message(cmsg); |
|---|
| 293 | | - _ls = cmsg->l - _l - 1; |
|---|
| 294 | | - if (_ls < 255) |
|---|
| 295 | | - (cmsg->m + _l)[0] = (u8) _ls; |
|---|
| 296 | | - else { |
|---|
| 297 | | - structTLcpyovl(cmsg->m + _l + 3, cmsg->m + _l + 1, _ls); |
|---|
| 298 | | - (cmsg->m + _l)[0] = 0xff; |
|---|
| 299 | | - wordTLcpy(cmsg->m + _l + 1, &_ls); |
|---|
| 300 | | - } |
|---|
| 301 | | - } |
|---|
| 302 | | - break; |
|---|
| 303 | | - } |
|---|
| 304 | | - } |
|---|
| 305 | | -} |
|---|
| 306 | | - |
|---|
| 307 | | -/** |
|---|
| 308 | | - * capi_cmsg2message() - assemble CAPI 2.0 message from _cmsg structure |
|---|
| 309 | | - * @cmsg: _cmsg structure |
|---|
| 310 | | - * @msg: buffer for assembled message |
|---|
| 311 | | - * |
|---|
| 312 | | - * Return value: 0 for success |
|---|
| 313 | | - */ |
|---|
| 314 | | - |
|---|
| 315 | | -unsigned capi_cmsg2message(_cmsg *cmsg, u8 *msg) |
|---|
| 316 | | -{ |
|---|
| 317 | | - cmsg->m = msg; |
|---|
| 318 | | - cmsg->l = 8; |
|---|
| 319 | | - cmsg->p = 0; |
|---|
| 320 | | - cmsg->par = capi_cmd2par(cmsg->Command, cmsg->Subcommand); |
|---|
| 321 | | - if (!cmsg->par) |
|---|
| 322 | | - return 1; /* invalid command/subcommand */ |
|---|
| 323 | | - |
|---|
| 324 | | - pars_2_message(cmsg); |
|---|
| 325 | | - |
|---|
| 326 | | - wordTLcpy(msg + 0, &cmsg->l); |
|---|
| 327 | | - byteTLcpy(cmsg->m + 4, &cmsg->Command); |
|---|
| 328 | | - byteTLcpy(cmsg->m + 5, &cmsg->Subcommand); |
|---|
| 329 | | - wordTLcpy(cmsg->m + 2, &cmsg->ApplId); |
|---|
| 330 | | - wordTLcpy(cmsg->m + 6, &cmsg->Messagenumber); |
|---|
| 331 | | - |
|---|
| 332 | | - return 0; |
|---|
| 333 | | -} |
|---|
| 334 | | - |
|---|
| 335 | | -/*-------------------------------------------------------*/ |
|---|
| 336 | | -static void message_2_pars(_cmsg *cmsg) |
|---|
| 337 | | -{ |
|---|
| 338 | | - for (; TYP != _CEND; cmsg->p++) { |
|---|
| 339 | | - |
|---|
| 340 | | - switch (TYP) { |
|---|
| 341 | | - case _CBYTE: |
|---|
| 342 | | - byteTRcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 343 | | - cmsg->l++; |
|---|
| 344 | | - break; |
|---|
| 345 | | - case _CWORD: |
|---|
| 346 | | - wordTRcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 347 | | - cmsg->l += 2; |
|---|
| 348 | | - break; |
|---|
| 349 | | - case _CDWORD: |
|---|
| 350 | | - dwordTRcpy(cmsg->m + cmsg->l, OFF); |
|---|
| 351 | | - cmsg->l += 4; |
|---|
| 352 | | - break; |
|---|
| 353 | | - case _CSTRUCT: |
|---|
| 354 | | - *(u8 **) OFF = cmsg->m + cmsg->l; |
|---|
| 355 | | - |
|---|
| 356 | | - if (cmsg->m[cmsg->l] != 0xff) |
|---|
| 357 | | - cmsg->l += 1 + cmsg->m[cmsg->l]; |
|---|
| 358 | | - else |
|---|
| 359 | | - cmsg->l += 3 + *(u16 *) (cmsg->m + cmsg->l + 1); |
|---|
| 360 | | - break; |
|---|
| 361 | | - case _CMSTRUCT: |
|---|
| 362 | | -/*----- Metastruktur 0 -----*/ |
|---|
| 363 | | - if (cmsg->m[cmsg->l] == '\0') { |
|---|
| 364 | | - *(_cmstruct *) OFF = CAPI_DEFAULT; |
|---|
| 365 | | - cmsg->l++; |
|---|
| 366 | | - jumpcstruct(cmsg); |
|---|
| 367 | | - } else { |
|---|
| 368 | | - unsigned _l = cmsg->l; |
|---|
| 369 | | - *(_cmstruct *) OFF = CAPI_COMPOSE; |
|---|
| 370 | | - cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1; |
|---|
| 371 | | - cmsg->p++; |
|---|
| 372 | | - message_2_pars(cmsg); |
|---|
| 373 | | - } |
|---|
| 374 | | - break; |
|---|
| 375 | | - } |
|---|
| 376 | | - } |
|---|
| 377 | | -} |
|---|
| 378 | | - |
|---|
| 379 | | -/** |
|---|
| 380 | | - * capi_message2cmsg() - disassemble CAPI 2.0 message into _cmsg structure |
|---|
| 381 | | - * @cmsg: _cmsg structure |
|---|
| 382 | | - * @msg: buffer for assembled message |
|---|
| 383 | | - * |
|---|
| 384 | | - * Return value: 0 for success |
|---|
| 385 | | - */ |
|---|
| 386 | | - |
|---|
| 387 | | -unsigned capi_message2cmsg(_cmsg *cmsg, u8 *msg) |
|---|
| 388 | | -{ |
|---|
| 389 | | - memset(cmsg, 0, sizeof(_cmsg)); |
|---|
| 390 | | - cmsg->m = msg; |
|---|
| 391 | | - cmsg->l = 8; |
|---|
| 392 | | - cmsg->p = 0; |
|---|
| 393 | | - byteTRcpy(cmsg->m + 4, &cmsg->Command); |
|---|
| 394 | | - byteTRcpy(cmsg->m + 5, &cmsg->Subcommand); |
|---|
| 395 | | - cmsg->par = capi_cmd2par(cmsg->Command, cmsg->Subcommand); |
|---|
| 396 | | - if (!cmsg->par) |
|---|
| 397 | | - return 1; /* invalid command/subcommand */ |
|---|
| 398 | | - |
|---|
| 399 | | - message_2_pars(cmsg); |
|---|
| 400 | | - |
|---|
| 401 | | - wordTRcpy(msg + 0, &cmsg->l); |
|---|
| 402 | | - wordTRcpy(cmsg->m + 2, &cmsg->ApplId); |
|---|
| 403 | | - wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber); |
|---|
| 404 | | - |
|---|
| 405 | | - return 0; |
|---|
| 406 | | -} |
|---|
| 407 | | - |
|---|
| 408 | | -/** |
|---|
| 409 | | - * capi_cmsg_header() - initialize header part of _cmsg structure |
|---|
| 410 | | - * @cmsg: _cmsg structure |
|---|
| 411 | | - * @_ApplId: ApplID field value |
|---|
| 412 | | - * @_Command: Command field value |
|---|
| 413 | | - * @_Subcommand: Subcommand field value |
|---|
| 414 | | - * @_Messagenumber: Message Number field value |
|---|
| 415 | | - * @_Controller: Controller/PLCI/NCCI field value |
|---|
| 416 | | - * |
|---|
| 417 | | - * Return value: 0 for success |
|---|
| 418 | | - */ |
|---|
| 419 | | - |
|---|
| 420 | | -unsigned capi_cmsg_header(_cmsg *cmsg, u16 _ApplId, |
|---|
| 421 | | - u8 _Command, u8 _Subcommand, |
|---|
| 422 | | - u16 _Messagenumber, u32 _Controller) |
|---|
| 423 | | -{ |
|---|
| 424 | | - memset(cmsg, 0, sizeof(_cmsg)); |
|---|
| 425 | | - cmsg->ApplId = _ApplId; |
|---|
| 426 | | - cmsg->Command = _Command; |
|---|
| 427 | | - cmsg->Subcommand = _Subcommand; |
|---|
| 428 | | - cmsg->Messagenumber = _Messagenumber; |
|---|
| 429 | | - cmsg->adr.adrController = _Controller; |
|---|
| 430 | | - return 0; |
|---|
| 431 | | -} |
|---|
| 432 | 250 | |
|---|
| 433 | 251 | /*-------------------------------------------------------*/ |
|---|
| 434 | 252 | |
|---|
| .. | .. |
|---|
| 560 | 378 | /*2e */ "Reject", |
|---|
| 561 | 379 | /*2f */ "Useruserdata" |
|---|
| 562 | 380 | }; |
|---|
| 563 | | - |
|---|
| 564 | | - |
|---|
| 565 | 381 | |
|---|
| 566 | 382 | #include <stdarg.h> |
|---|
| 567 | 383 | |
|---|
| .. | .. |
|---|
| 800 | 616 | return cdb; |
|---|
| 801 | 617 | } |
|---|
| 802 | 618 | |
|---|
| 803 | | -/** |
|---|
| 804 | | - * capi_cmsg2str() - format _cmsg structure for printing |
|---|
| 805 | | - * @cmsg: _cmsg structure |
|---|
| 806 | | - * |
|---|
| 807 | | - * Allocates a CAPI debug buffer and fills it with a printable representation |
|---|
| 808 | | - * of the CAPI 2.0 message stored in @cmsg by a previous call to |
|---|
| 809 | | - * capi_cmsg2message() or capi_message2cmsg(). |
|---|
| 810 | | - * Return value: allocated debug buffer, NULL on error |
|---|
| 811 | | - * The returned buffer should be freed by a call to cdebbuf_free() after use. |
|---|
| 812 | | - */ |
|---|
| 813 | | - |
|---|
| 814 | | -_cdebbuf *capi_cmsg2str(_cmsg *cmsg) |
|---|
| 815 | | -{ |
|---|
| 816 | | - _cdebbuf *cdb; |
|---|
| 817 | | - |
|---|
| 818 | | - if (!cmsg->m) |
|---|
| 819 | | - return NULL; /* no message */ |
|---|
| 820 | | - cdb = cdebbuf_alloc(); |
|---|
| 821 | | - if (!cdb) |
|---|
| 822 | | - return NULL; |
|---|
| 823 | | - cmsg->l = 8; |
|---|
| 824 | | - cmsg->p = 0; |
|---|
| 825 | | - cdb = bufprint(cdb, "%s ID=%03d #0x%04x LEN=%04d\n", |
|---|
| 826 | | - capi_cmd2str(cmsg->Command, cmsg->Subcommand), |
|---|
| 827 | | - ((u16 *) cmsg->m)[1], |
|---|
| 828 | | - ((u16 *) cmsg->m)[3], |
|---|
| 829 | | - ((u16 *) cmsg->m)[0]); |
|---|
| 830 | | - cdb = protocol_message_2_pars(cdb, cmsg, 1); |
|---|
| 831 | | - return cdb; |
|---|
| 832 | | -} |
|---|
| 833 | | - |
|---|
| 834 | 619 | int __init cdebug_init(void) |
|---|
| 835 | 620 | { |
|---|
| 836 | 621 | g_cmsg = kmalloc(sizeof(_cmsg), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 854 | 639 | return 0; |
|---|
| 855 | 640 | } |
|---|
| 856 | 641 | |
|---|
| 857 | | -void __exit cdebug_exit(void) |
|---|
| 642 | +void cdebug_exit(void) |
|---|
| 858 | 643 | { |
|---|
| 859 | 644 | if (g_debbuf) |
|---|
| 860 | 645 | kfree(g_debbuf->buf); |
|---|
| .. | .. |
|---|
| 885 | 670 | return 0; |
|---|
| 886 | 671 | } |
|---|
| 887 | 672 | |
|---|
| 888 | | -void __exit cdebug_exit(void) |
|---|
| 673 | +void cdebug_exit(void) |
|---|
| 889 | 674 | { |
|---|
| 890 | 675 | } |
|---|
| 891 | 676 | |
|---|
| 892 | 677 | #endif |
|---|
| 893 | | - |
|---|
| 894 | | -EXPORT_SYMBOL(cdebbuf_free); |
|---|
| 895 | | -EXPORT_SYMBOL(capi_cmsg2message); |
|---|
| 896 | | -EXPORT_SYMBOL(capi_message2cmsg); |
|---|
| 897 | | -EXPORT_SYMBOL(capi_cmsg_header); |
|---|
| 898 | | -EXPORT_SYMBOL(capi_cmd2str); |
|---|
| 899 | | -EXPORT_SYMBOL(capi_cmsg2str); |
|---|
| 900 | | -EXPORT_SYMBOL(capi_message2str); |
|---|