void hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) { __u16 appl_id; int _len, _len2; __u8 msghead[64]; appl_id = CAPIMSG_APPID(skb->data); switch(_hycapi_appCheck(appl_id, ctrl->cnr)) { case 0: /* printk(KERN_INFO "Need to register\n"); */ hycapi_register_internal(ctrl, appl_id, &(hycapi_applications[appl_id-1].rp)); break; case 1: break; default: printk(KERN_ERR "HYCAPI: Controller mixup!\n"); return; } switch(CAPIMSG_CMD(skb->data)) { case CAPI_DISCONNECT_B3_RESP: ctrl->free_ncci(ctrl, appl_id, CAPIMSG_NCCI(skb->data)); break; case CAPI_DATA_B3_REQ: _len = CAPIMSG_LEN(skb->data); if (_len > 22) { _len2 = _len - 22; memcpy(msghead, skb->data, 22); memcpy(skb->data + _len2, msghead, 22); skb_pull(skb, _len2); CAPIMSG_SETLEN(skb->data, 22); } break; case CAPI_LISTEN_REQ: if(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1]) { kfree_skb(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1]); hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = NULL; } if (!(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = skb_copy(skb, GFP_ATOMIC))) { printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n"); } break; default: break; } hycapi_sendmsg_internal(ctrl, skb); }
void hycapi_rx_capipkt(hysdn_card *card, unsigned char *buf, unsigned short len) { struct sk_buff *skb; hycapictrl_info *cinfo = card->hyctrlinfo; struct capi_ctr *ctrl; __u16 ApplId; __u16 MsgLen, info; __u16 len2, CapiCmd; __u32 CP64[2] = {0, 0}; #ifdef HYCAPI_PRINTFNAMES printk(KERN_NOTICE "hycapi_rx_capipkt\n"); #endif if (!cinfo) { return; } ctrl = &cinfo->capi_ctrl; if (len < CAPI_MSG_BASELEN) { printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, length %d!\n", card->myid, len); return; } MsgLen = CAPIMSG_LEN(buf); ApplId = CAPIMSG_APPID(buf); CapiCmd = CAPIMSG_CMD(buf); if ((CapiCmd == CAPI_DATA_B3_IND) && (MsgLen < 30)) { len2 = len + (30 - MsgLen); if (!(skb = alloc_skb(len2, GFP_ATOMIC))) { printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n", card->myid); return; } memcpy(skb_put(skb, MsgLen), buf, MsgLen); memcpy(skb_put(skb, 2 * sizeof(__u32)), CP64, 2 * sizeof(__u32)); memcpy(skb_put(skb, len - MsgLen), buf + MsgLen, len - MsgLen); CAPIMSG_SETLEN(skb->data, 30); } else { if (!(skb = alloc_skb(len, GFP_ATOMIC))) { printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n", card->myid); return; } memcpy(skb_put(skb, len), buf, len); } switch (CAPIMSG_CMD(skb->data)) { case CAPI_CONNECT_B3_CONF: /* Check info-field for error-indication: */ info = CAPIMSG_U16(skb->data, 12); switch (info) { case 0: capilib_new_ncci(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data), hycapi_applications[ApplId - 1].rp.datablkcnt); break; case 0x0001: printk(KERN_ERR "HYSDN Card%d: NCPI not supported by current " "protocol. NCPI ignored.\n", card->myid); break; case 0x2001: printk(KERN_ERR "HYSDN Card%d: Message not supported in" " current state\n", card->myid); break; case 0x2002: printk(KERN_ERR "HYSDN Card%d: invalid PLCI\n", card->myid); break; case 0x2004: printk(KERN_ERR "HYSDN Card%d: out of NCCI\n", card->myid); break; case 0x3008: printk(KERN_ERR "HYSDN Card%d: NCPI not supported\n", card->myid); break; default: printk(KERN_ERR "HYSDN Card%d: Info in CONNECT_B3_CONF: %d\n", card->myid, info); break; } break; case CAPI_CONNECT_B3_IND: capilib_new_ncci(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data), hycapi_applications[ApplId - 1].rp.datablkcnt); break; case CAPI_DATA_B3_CONF: capilib_data_b3_conf(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data), CAPIMSG_MSGID(skb->data)); break; default: break; } capi_ctr_handle_message(ctrl, ApplId, skb); }
static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) { __u16 appl_id; int _len, _len2; __u8 msghead[64]; hycapictrl_info *cinfo = ctrl->driverdata; u16 retval = CAPI_NOERROR; appl_id = CAPIMSG_APPID(skb->data); switch (_hycapi_appCheck(appl_id, ctrl->cnr)) { case 0: /* printk(KERN_INFO "Need to register\n"); */ hycapi_register_internal(ctrl, appl_id, &(hycapi_applications[appl_id - 1].rp)); break; case 1: break; default: printk(KERN_ERR "HYCAPI: Controller mixup!\n"); retval = CAPI_ILLAPPNR; goto out; } switch (CAPIMSG_CMD(skb->data)) { case CAPI_DISCONNECT_B3_RESP: capilib_free_ncci(&cinfo->ncci_head, appl_id, CAPIMSG_NCCI(skb->data)); break; case CAPI_DATA_B3_REQ: _len = CAPIMSG_LEN(skb->data); if (_len > 22) { _len2 = _len - 22; skb_copy_from_linear_data(skb, msghead, 22); skb_copy_to_linear_data_offset(skb, _len2, msghead, 22); skb_pull(skb, _len2); CAPIMSG_SETLEN(skb->data, 22); retval = capilib_data_b3_req(&cinfo->ncci_head, CAPIMSG_APPID(skb->data), CAPIMSG_NCCI(skb->data), CAPIMSG_MSGID(skb->data)); } break; case CAPI_LISTEN_REQ: if (hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1]) { kfree_skb(hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1]); hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1] = NULL; } if (!(hycapi_applications[appl_id -1].listen_req[ctrl->cnr - 1] = skb_copy(skb, GFP_ATOMIC))) { printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n"); } break; default: break; } out: if (retval == CAPI_NOERROR) hycapi_sendmsg_internal(ctrl, skb); else dev_kfree_skb_any(skb); return retval; }
static void c4_handle_rx(avmcard *card) { avmcard_dmainfo *dma = card->dma; struct capi_ctr *ctrl; avmctrl_info *cinfo; struct sk_buff *skb; void *p = dma->recvbuf.dmabuf; u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; u8 b1cmd = _get_byte(&p); u32 cidx; #ifdef AVM_C4_DEBUG printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name, b1cmd, (unsigned long)dma->recvlen); #endif switch (b1cmd) { case RECEIVE_DATA_B3_IND: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); DataB3Len = _get_slice(&p, card->databuf); cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr; if (cidx >= card->nlogcontr) cidx = 0; ctrl = &card->ctrlinfo[cidx].capi_ctrl; if (MsgLen < 30) { /* not CAPI 64Bit */ memset(card->msgbuf+MsgLen, 0, 30-MsgLen); MsgLen = 30; CAPIMSG_SETLEN(card->msgbuf, 30); } if (!(skb = alloc_skb(DataB3Len+MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len); capi_ctr_handle_message(ctrl, ApplId, skb); } break; case RECEIVE_MESSAGE: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr; if (cidx >= card->nlogcontr) cidx = 0; cinfo = &card->ctrlinfo[cidx]; ctrl = &card->ctrlinfo[cidx].capi_ctrl; if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF) capilib_data_b3_conf(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data), CAPIMSG_MSGID(skb->data)); capi_ctr_handle_message(ctrl, ApplId, skb); } break; case RECEIVE_NEW_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); WindowSize = _get_word(&p); cidx = (NCCI&0x7f) - card->cardnr; if (cidx >= card->nlogcontr) cidx = 0; capilib_new_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI, WindowSize); break; case RECEIVE_FREE_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); if (NCCI != 0xffffffff) { cidx = (NCCI&0x7f) - card->cardnr; if (cidx >= card->nlogcontr) cidx = 0; capilib_free_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI); } break; case RECEIVE_START: #ifdef AVM_C4_POLLDEBUG printk(KERN_INFO "%s: poll from c4\n", card->name); #endif if (!suppress_pollack) queue_pollack(card); for (cidx=0; cidx < card->nr_controllers; cidx++) { ctrl = &card->ctrlinfo[cidx].capi_ctrl; capi_ctr_resume_output(ctrl); } break; case RECEIVE_STOP: for (cidx=0; cidx < card->nr_controllers; cidx++) { ctrl = &card->ctrlinfo[cidx].capi_ctrl; capi_ctr_suspend_output(ctrl); } break; case RECEIVE_INIT: cidx = card->nlogcontr; if (cidx >= card->nr_controllers) { printk(KERN_ERR "%s: card with %d controllers ??\n", card->name, cidx+1); break; } card->nlogcontr++; cinfo = &card->ctrlinfo[cidx]; ctrl = &cinfo->capi_ctrl; cinfo->versionlen = _get_slice(&p, cinfo->versionbuf); b1_parse_version(cinfo); printk(KERN_INFO "%s: %s-card (%s) now active\n", card->name, cinfo->version[VER_CARDTYPE], cinfo->version[VER_DRIVER]); capi_ctr_ready(&cinfo->capi_ctrl); break; case RECEIVE_TASK_READY: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen] = 0; while ( MsgLen > 0 && ( card->msgbuf[MsgLen-1] == '\n' || card->msgbuf[MsgLen-1] == '\r')) { card->msgbuf[MsgLen-1] = 0; MsgLen--; } printk(KERN_INFO "%s: task %d \"%s\" ready.\n", card->name, ApplId, card->msgbuf); break; case RECEIVE_DEBUGMSG: MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen] = 0; while ( MsgLen > 0 && ( card->msgbuf[MsgLen-1] == '\n' || card->msgbuf[MsgLen-1] == '\r')) { card->msgbuf[MsgLen-1] = 0; MsgLen--; } printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf); break; default: printk(KERN_ERR "%s: c4_interrupt: 0x%x ???\n", card->name, b1cmd); return; } }
static void b1dma_handle_rx(avmcard *card) { avmctrl_info *cinfo = &card->ctrlinfo[0]; avmcard_dmainfo *dma = card->dma; struct capi_ctr *ctrl = cinfo->capi_ctrl; struct sk_buff *skb; void *p = dma->recvbuf+4; __u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; __u8 b1cmd = _get_byte(&p); #ifdef CONFIG_B1DMA_DEBUG printk(KERN_DEBUG "rx: 0x%x %lu\n", b1cmd, (unsigned long)dma->recvlen); #endif switch (b1cmd) { case RECEIVE_DATA_B3_IND: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); DataB3Len = _get_slice(&p, card->databuf); if (MsgLen < 30) { /* not CAPI 64Bit */ memset(card->msgbuf+MsgLen, 0, 30-MsgLen); MsgLen = 30; CAPIMSG_SETLEN(card->msgbuf, 30); } if (!(skb = alloc_skb(DataB3Len+MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len); ctrl->handle_capimsg(ctrl, ApplId, skb); } break; case RECEIVE_MESSAGE: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) { printk(KERN_ERR "%s: incoming packet dropped\n", card->name); } else { memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); ctrl->handle_capimsg(ctrl, ApplId, skb); } break; case RECEIVE_NEW_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); WindowSize = _get_word(&p); ctrl->new_ncci(ctrl, ApplId, NCCI, WindowSize); break; case RECEIVE_FREE_NCCI: ApplId = _get_word(&p); NCCI = _get_word(&p); if (NCCI != 0xffffffff) ctrl->free_ncci(ctrl, ApplId, NCCI); else ctrl->appl_released(ctrl, ApplId); break; case RECEIVE_START: #ifdef CONFIG_B1DMA_POLLDEBUG printk(KERN_INFO "%s: receive poll\n", card->name); #endif if (!suppress_pollack) queue_pollack(card); ctrl->resume_output(ctrl); break; case RECEIVE_STOP: ctrl->suspend_output(ctrl); break; case RECEIVE_INIT: cinfo->versionlen = _get_slice(&p, cinfo->versionbuf); b1_parse_version(cinfo); printk(KERN_INFO "%s: %s-card (%s) now active\n", card->name, cinfo->version[VER_CARDTYPE], cinfo->version[VER_DRIVER]); ctrl->ready(ctrl); break; case RECEIVE_TASK_READY: ApplId = (unsigned) _get_word(&p); MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen] = 0; while ( MsgLen > 0 && ( card->msgbuf[MsgLen-1] == '\n' || card->msgbuf[MsgLen-1] == '\r')) { card->msgbuf[MsgLen-1] = 0; MsgLen--; } printk(KERN_INFO "%s: task %d \"%s\" ready.\n", card->name, ApplId, card->msgbuf); break; case RECEIVE_DEBUGMSG: MsgLen = _get_slice(&p, card->msgbuf); card->msgbuf[MsgLen] = 0; while ( MsgLen > 0 && ( card->msgbuf[MsgLen-1] == '\n' || card->msgbuf[MsgLen-1] == '\r')) { card->msgbuf[MsgLen-1] = 0; MsgLen--; } printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf); break; default: printk(KERN_ERR "%s: b1dma_interrupt: 0x%x ???\n", card->name, b1cmd); return; } }