_cdebbuf *capi_message2str(u8 * msg) { _cdebbuf *cdb; _cmsg *cmsg; cdb = cdebbuf_alloc(); if (unlikely(!cdb)) return NULL; if (likely(cdb == g_debbuf)) cmsg = g_cmsg; else cmsg = kmalloc(sizeof(_cmsg), GFP_ATOMIC); if (unlikely(!cmsg)) { cdebbuf_free(cdb); return NULL; } cmsg->m = msg; cmsg->l = 8; cmsg->p = 0; byteTRcpy(cmsg->m + 4, &cmsg->Command); byteTRcpy(cmsg->m + 5, &cmsg->Subcommand); cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)]; cdb = bufprint(cdb, "%-26s ID=%03d #0x%04x LEN=%04d\n", mnames[command_2_index(cmsg->Command, cmsg->Subcommand)], ((unsigned short *) msg)[1], ((unsigned short *) msg)[3], ((unsigned short *) msg)[0]); cdb = protocol_message_2_pars(cdb, cmsg, 1); if (unlikely(cmsg != g_cmsg)) kfree(cmsg); return cdb; }
unsigned capi_message2cmsg(_cmsg * cmsg, u8 * msg) { memset(cmsg, 0, sizeof(_cmsg)); cmsg->m = msg; cmsg->l = 8; cmsg->p = 0; byteTRcpy(cmsg->m + 4, &cmsg->Command); byteTRcpy(cmsg->m + 5, &cmsg->Subcommand); cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)]; message_2_pars(cmsg); wordTRcpy(msg + 0, &cmsg->l); wordTRcpy(cmsg->m + 2, &cmsg->ApplId); wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber); return 0; }
/*-------------------------------------------------------*/ char *capi_message2str(__u8 * msg) { _cmsg cmsg; p = buf; p[0] = 0; cmsg.m = msg; cmsg.l = 8; cmsg.p = 0; byteTRcpy(cmsg.m + 4, &cmsg.Command); byteTRcpy(cmsg.m + 5, &cmsg.Subcommand); cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)]; bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n", mnames[command_2_index(cmsg.Command, cmsg.Subcommand)], ((unsigned short *) msg)[1], ((unsigned short *) msg)[3], ((unsigned short *) msg)[0]); protocol_message_2_pars(&cmsg, 1); return buf; }
static void message_2_pars(_cmsg * cmsg) { for (; TYP != _CEND; cmsg->p++) { switch (TYP) { case _CBYTE: byteTRcpy(cmsg->m + cmsg->l, OFF); cmsg->l++; break; case _CWORD: wordTRcpy(cmsg->m + cmsg->l, OFF); cmsg->l += 2; break; case _CDWORD: dwordTRcpy(cmsg->m + cmsg->l, OFF); cmsg->l += 4; break; case _CSTRUCT: *(u8 **) OFF = cmsg->m + cmsg->l; if (cmsg->m[cmsg->l] != 0xff) cmsg->l += 1 + cmsg->m[cmsg->l]; else cmsg->l += 3 + *(u16 *) (cmsg->m + cmsg->l + 1); break; case _CMSTRUCT: if (cmsg->m[cmsg->l] == '\0') { *(_cmstruct *) OFF = CAPI_DEFAULT; cmsg->l++; jumpcstruct(cmsg); } else { unsigned _l = cmsg->l; *(_cmstruct *) OFF = CAPI_COMPOSE; cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1; cmsg->p++; message_2_pars(cmsg); } break; } } }