i4l.c
来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 575 行 · 第 1/2 页
C
575 行
/* * Stuff used by all variants of the driver * * Copyright (c) 2001 by Stefan Eilers, * Hansjoerg Lipp <hjlipp@web.de>, * Tilman Schmidt <tilman@imap.cc>. * * ===================================================================== * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * ===================================================================== */#include "gigaset.h"/* == Handling of I4L IO =====================================================*//* writebuf_from_LL * called by LL to transmit data on an open channel * inserts the buffer data into the send queue and starts the transmission * Note that this operation must not sleep! * When the buffer is processed completely, gigaset_skb_sent() should be called. * parameters: * driverID driver ID as assigned by LL * channel channel number * ack if != 0 LL wants to be notified on completion via * statcallb(ISDN_STAT_BSENT) * skb skb containing data to send * return value: * number of accepted bytes * 0 if temporarily unable to accept data (out of buffer space) * <0 on error (eg. -EINVAL) */static int writebuf_from_LL(int driverID, int channel, int ack, struct sk_buff *skb){ struct cardstate *cs; struct bc_state *bcs; unsigned len; unsigned skblen; if (!(cs = gigaset_get_cs_by_id(driverID))) { err("%s: invalid driver ID (%d)", __func__, driverID); return -ENODEV; } if (channel < 0 || channel >= cs->channels) { err("%s: invalid channel ID (%d)", __func__, channel); return -ENODEV; } bcs = &cs->bcs[channel]; len = skb->len; gig_dbg(DEBUG_LLDATA, "Receiving data from LL (id: %d, ch: %d, ack: %d, sz: %d)", driverID, channel, ack, len); if (!len) { if (ack) notice("%s: not ACKing empty packet", __func__); return 0; } if (len > MAX_BUF_SIZE) { err("%s: packet too large (%d bytes)", __func__, len); return -EINVAL; } skblen = ack ? len : 0; skb->head[0] = skblen & 0xff; skb->head[1] = skblen >> 8; gig_dbg(DEBUG_MCMD, "skb: len=%u, skblen=%u: %02x %02x", len, skblen, (unsigned) skb->head[0], (unsigned) skb->head[1]); /* pass to device-specific module */ return cs->ops->send_skb(bcs, skb);}void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb){ unsigned len; isdn_ctrl response; ++bcs->trans_up; if (skb->len) dev_warn(bcs->cs->dev, "%s: skb->len==%d\n", __func__, skb->len); len = (unsigned char) skb->head[0] | (unsigned) (unsigned char) skb->head[1] << 8; if (len) { gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)", bcs->cs->myid, bcs->channel, len); response.driver = bcs->cs->myid; response.command = ISDN_STAT_BSENT; response.arg = bcs->channel; response.parm.length = len; bcs->cs->iif.statcallb(&response); }}EXPORT_SYMBOL_GPL(gigaset_skb_sent);/* This function will be called by LL to send commands * NOTE: LL ignores the returned value, for commands other than ISDN_CMD_IOCTL, * so don't put too much effort into it. */static int command_from_LL(isdn_ctrl *cntrl){ struct cardstate *cs = gigaset_get_cs_by_id(cntrl->driver); //isdn_ctrl response; //unsigned long flags; struct bc_state *bcs; int retval = 0; struct setup_parm *sp; unsigned param; unsigned long flags; gigaset_debugdrivers(); if (!cs) { warn("LL tried to access unknown device with nr. %d", cntrl->driver); return -ENODEV; } switch (cntrl->command) { case ISDN_CMD_IOCTL: gig_dbg(DEBUG_ANY, "ISDN_CMD_IOCTL (driver: %d, arg: %ld)", cntrl->driver, cntrl->arg); warn("ISDN_CMD_IOCTL is not supported."); return -EINVAL; case ISDN_CMD_DIAL: gig_dbg(DEBUG_ANY, "ISDN_CMD_DIAL (driver: %d, ch: %ld, " "phone: %s, ownmsn: %s, si1: %d, si2: %d)", cntrl->driver, cntrl->arg, cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn, cntrl->parm.setup.si1, cntrl->parm.setup.si2); if (cntrl->arg >= cs->channels) { err("ISDN_CMD_DIAL: invalid channel (%d)", (int) cntrl->arg); return -EINVAL; } bcs = cs->bcs + cntrl->arg; if (!gigaset_get_channel(bcs)) { err("ISDN_CMD_DIAL: channel not free"); return -EBUSY; } sp = kmalloc(sizeof *sp, GFP_ATOMIC); if (!sp) { gigaset_free_channel(bcs); err("ISDN_CMD_DIAL: out of memory"); return -ENOMEM; } *sp = cntrl->parm.setup; spin_lock_irqsave(&cs->lock, flags); param = bcs->at_state.seq_index; spin_unlock_irqrestore(&cs->lock, flags); if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, sp, param, NULL)) { //FIXME what should we do? kfree(sp); gigaset_free_channel(bcs); return -ENOMEM; } gig_dbg(DEBUG_CMD, "scheduling DIAL"); gigaset_schedule_event(cs); break; case ISDN_CMD_ACCEPTD: //FIXME gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTD"); if (cntrl->arg >= cs->channels) { err("ISDN_CMD_ACCEPTD: invalid channel (%d)", (int) cntrl->arg); return -EINVAL; } if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, EV_ACCEPT, NULL, 0, NULL)) { //FIXME what should we do? return -ENOMEM; } gig_dbg(DEBUG_CMD, "scheduling ACCEPT"); gigaset_schedule_event(cs); break; case ISDN_CMD_ACCEPTB: gig_dbg(DEBUG_ANY, "ISDN_CMD_ACCEPTB"); break; case ISDN_CMD_HANGUP: gig_dbg(DEBUG_ANY, "ISDN_CMD_HANGUP (ch: %d)", (int) cntrl->arg); if (cntrl->arg >= cs->channels) { err("ISDN_CMD_HANGUP: invalid channel (%u)", (unsigned) cntrl->arg); return -EINVAL; } if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg].at_state, EV_HUP, NULL, 0, NULL)) { //FIXME what should we do? return -ENOMEM; } gig_dbg(DEBUG_CMD, "scheduling HUP"); gigaset_schedule_event(cs); break; case ISDN_CMD_CLREAZ: /* Do not signal incoming signals */ //FIXME gig_dbg(DEBUG_ANY, "ISDN_CMD_CLREAZ"); break; case ISDN_CMD_SETEAZ: /* Signal incoming calls for given MSN */ //FIXME gig_dbg(DEBUG_ANY, "ISDN_CMD_SETEAZ (id: %d, ch: %ld, number: %s)", cntrl->driver, cntrl->arg, cntrl->parm.num); break; case ISDN_CMD_SETL2: /* Set L2 to given protocol */ gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL2 (ch: %ld, proto: %lx)", cntrl->arg & 0xff, (cntrl->arg >> 8)); if ((cntrl->arg & 0xff) >= cs->channels) { err("ISDN_CMD_SETL2: invalid channel (%u)", (unsigned) cntrl->arg & 0xff); return -EINVAL; } if (!gigaset_add_event(cs, &cs->bcs[cntrl->arg & 0xff].at_state, EV_PROTO_L2, NULL, cntrl->arg >> 8, NULL)) { //FIXME what should we do? return -ENOMEM; } gig_dbg(DEBUG_CMD, "scheduling PROTO_L2"); gigaset_schedule_event(cs); break; case ISDN_CMD_SETL3: /* Set L3 to given protocol */ gig_dbg(DEBUG_ANY, "ISDN_CMD_SETL3 (ch: %ld, proto: %lx)", cntrl->arg & 0xff, (cntrl->arg >> 8)); if ((cntrl->arg & 0xff) >= cs->channels) { err("ISDN_CMD_SETL3: invalid channel (%u)", (unsigned) cntrl->arg & 0xff); return -EINVAL; } if (cntrl->arg >> 8 != ISDN_PROTO_L3_TRANS) { err("ISDN_CMD_SETL3: invalid protocol %lu", cntrl->arg >> 8); return -EINVAL; } break; case ISDN_CMD_PROCEED: gig_dbg(DEBUG_ANY, "ISDN_CMD_PROCEED"); //FIXME break; case ISDN_CMD_ALERT: gig_dbg(DEBUG_ANY, "ISDN_CMD_ALERT"); //FIXME if (cntrl->arg >= cs->channels) { err("ISDN_CMD_ALERT: invalid channel (%d)", (int) cntrl->arg); return -EINVAL; } //bcs = cs->bcs + cntrl->arg; //bcs->proto2 = -1; // FIXME break; case ISDN_CMD_REDIR: gig_dbg(DEBUG_ANY, "ISDN_CMD_REDIR"); //FIXME break; case ISDN_CMD_PROT_IO: gig_dbg(DEBUG_ANY, "ISDN_CMD_PROT_IO"); break; case ISDN_CMD_FAXCMD: gig_dbg(DEBUG_ANY, "ISDN_CMD_FAXCMD");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?