include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / isdn / gigaset / i4l.c
index aca72a0..c99fb97 100644 (file)
@@ -15,6 +15,7 @@
 
 #include "gigaset.h"
 #include <linux/isdnif.h>
+#include <linux/slab.h>
 
 #define HW_HDR_LEN     2       /* Header size used to store ack info */
 
 static int writebuf_from_LL(int driverID, int channel, int ack,
                            struct sk_buff *skb)
 {
-       struct cardstate *cs;
+       struct cardstate *cs = gigaset_get_cs_by_id(driverID);
        struct bc_state *bcs;
+       unsigned char *ack_header;
        unsigned len;
-       unsigned skblen;
 
-       if (!(cs = gigaset_get_cs_by_id(driverID))) {
+       if (!cs) {
                pr_err("%s: invalid driver ID (%d)\n", __func__, driverID);
                return -ENODEV;
        }
@@ -78,11 +79,23 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
                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]);
+       /* set up acknowledgement header */
+       if (skb_headroom(skb) < HW_HDR_LEN) {
+               /* should never happen */
+               dev_err(cs->dev, "%s: insufficient skb headroom\n", __func__);
+               return -ENOMEM;
+       }
+       skb_set_mac_header(skb, -HW_HDR_LEN);
+       skb->mac_len = HW_HDR_LEN;
+       ack_header = skb_mac_header(skb);
+       if (ack) {
+               ack_header[0] = len & 0xff;
+               ack_header[1] = len >> 8;
+       } else {
+               ack_header[0] = ack_header[1] = 0;
+       }
+       gig_dbg(DEBUG_MCMD, "skb: len=%u, ack=%d: %02x %02x",
+               len, ack, ack_header[0], ack_header[1]);
 
        /* pass to device-specific module */
        return cs->ops->send_skb(bcs, skb);
@@ -99,6 +112,7 @@ static int writebuf_from_LL(int driverID, int channel, int ack,
 void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
 {
        isdn_if *iif = bcs->cs->iif;
+       unsigned char *ack_header = skb_mac_header(skb);
        unsigned len;
        isdn_ctrl response;
 
@@ -108,8 +122,7 @@ void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
                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;
+       len = ack_header[0] + ((unsigned) ack_header[1] << 8);
        if (len) {
                gig_dbg(DEBUG_MCMD, "ACKing to LL (id: %d, ch: %d, sz: %u)",
                        bcs->cs->myid, bcs->channel, len);
@@ -204,7 +217,7 @@ static int command_from_LL(isdn_ctrl *cntrl)
                return -EINVAL;
 
        case ISDN_CMD_DIAL:
-               gig_dbg(DEBUG_ANY,
+               gig_dbg(DEBUG_CMD,
                        "ISDN_CMD_DIAL (phone: %s, msn: %s, si1: %d, si2: %d)",
                        cntrl->parm.setup.phone, cntrl->parm.setup.eazmsn,
                        cntrl->parm.setup.si1, cntrl->parm.setup.si2);
@@ -292,11 +305,10 @@ static int command_from_LL(isdn_ctrl *cntrl)
                        gigaset_free_channel(bcs);
                        return -ENOMEM;
                }
-
-               gig_dbg(DEBUG_CMD, "scheduling DIAL");
                gigaset_schedule_event(cs);
                break;
        case ISDN_CMD_ACCEPTD:
+               gig_dbg(DEBUG_CMD, "ISDN_CMD_ACCEPTD");
                if (ch >= cs->channels) {
                        dev_err(cs->dev,
                                "ISDN_CMD_ACCEPTD: invalid channel (%d)\n", ch);
@@ -306,14 +318,11 @@ static int command_from_LL(isdn_ctrl *cntrl)
                if (!gigaset_add_event(cs, &bcs->at_state,
                                       EV_ACCEPT, NULL, 0, NULL))
                        return -ENOMEM;
-
-               gig_dbg(DEBUG_CMD, "scheduling ACCEPT");
                gigaset_schedule_event(cs);
 
                break;
-       case ISDN_CMD_ACCEPTB:
-               break;
        case ISDN_CMD_HANGUP:
+               gig_dbg(DEBUG_CMD, "ISDN_CMD_HANGUP");
                if (ch >= cs->channels) {
                        dev_err(cs->dev,
                                "ISDN_CMD_HANGUP: invalid channel (%d)\n", ch);
@@ -323,8 +332,6 @@ static int command_from_LL(isdn_ctrl *cntrl)
                if (!gigaset_add_event(cs, &bcs->at_state,
                                       EV_HUP, NULL, 0, NULL))
                        return -ENOMEM;
-
-               gig_dbg(DEBUG_CMD, "scheduling HUP");
                gigaset_schedule_event(cs);
 
                break;
@@ -364,6 +371,7 @@ static int command_from_LL(isdn_ctrl *cntrl)
                }
                break;
        case ISDN_CMD_SETL3: /* Set L3 to given protocol */
+               gig_dbg(DEBUG_CMD, "ISDN_CMD_SETL3");
                if (ch >= cs->channels) {
                        dev_err(cs->dev,
                                "ISDN_CMD_SETL3: invalid channel (%d)\n", ch);
@@ -378,47 +386,9 @@ static int command_from_LL(isdn_ctrl *cntrl)
                }
 
                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) {
-                       dev_err(cs->dev,
-                               "ISDN_CMD_ALERT: invalid channel (%d)\n",
-                               (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");
-               break;
-       case ISDN_CMD_GETL2:
-               gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL2");
-               break;
-       case ISDN_CMD_GETL3:
-               gig_dbg(DEBUG_ANY, "ISDN_CMD_GETL3");
-               break;
-       case ISDN_CMD_GETEAZ:
-               gig_dbg(DEBUG_ANY, "ISDN_CMD_GETEAZ");
-               break;
-       case ISDN_CMD_SETSIL:
-               gig_dbg(DEBUG_ANY, "ISDN_CMD_SETSIL");
-               break;
-       case ISDN_CMD_GETSIL:
-               gig_dbg(DEBUG_ANY, "ISDN_CMD_GETSIL");
-               break;
+
        default:
-               dev_err(cs->dev, "unknown command %d from LL\n",
+               gig_dbg(DEBUG_CMD, "unknown command %d from LL",
                        cntrl->command);
                return -EINVAL;
        }
@@ -474,7 +444,7 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
        /* fill ICALL structure */
        response.parm.setup.si1 = 0;    /* default: unknown */
        response.parm.setup.si2 = 0;
-       response.parm.setup.screen = 0; //FIXME how to set these?
+       response.parm.setup.screen = 0;
        response.parm.setup.plan = 0;
        if (!at_state->str_var[STR_ZBC]) {
                /* no BC (internal call): assume speech, A-law */
@@ -495,26 +465,24 @@ int gigaset_isdn_icall(struct at_state_t *at_state)
                return ICALL_IGNORE;
        }
        if (at_state->str_var[STR_NMBR]) {
-               strncpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
-                       sizeof response.parm.setup.phone - 1);
-               response.parm.setup.phone[sizeof response.parm.setup.phone - 1] = 0;
+               strlcpy(response.parm.setup.phone, at_state->str_var[STR_NMBR],
+                       sizeof response.parm.setup.phone);
        } else
                response.parm.setup.phone[0] = 0;
        if (at_state->str_var[STR_ZCPN]) {
-               strncpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
-                       sizeof response.parm.setup.eazmsn - 1);
-               response.parm.setup.eazmsn[sizeof response.parm.setup.eazmsn - 1] = 0;
+               strlcpy(response.parm.setup.eazmsn, at_state->str_var[STR_ZCPN],
+                       sizeof response.parm.setup.eazmsn);
        } else
                response.parm.setup.eazmsn[0] = 0;
 
        if (!bcs) {
                dev_notice(cs->dev, "no channel for incoming call\n");
                response.command = ISDN_STAT_ICALLW;
-               response.arg = 0; //FIXME
+               response.arg = 0;
        } else {
                gig_dbg(DEBUG_CMD, "Sending ICALL");
                response.command = ISDN_STAT_ICALL;
-               response.arg = bcs->channel; //FIXME
+               response.arg = bcs->channel;
        }
        response.driver = cs->myid;
        retval = iif->statcallb(&response);
@@ -625,15 +593,13 @@ void gigaset_isdn_stop(struct cardstate *cs)
 }
 
 /**
- * gigaset_isdn_register() - register to LL
+ * gigaset_isdn_regdev() - register to LL
  * @cs:                device descriptor structure.
  * @isdnid:    device name.
  *
- * Called by main module to register the device with the LL.
- *
  * Return value: 1 for success, 0 for failure
  */
-int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
+int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
 {
        isdn_if *iif;
 
@@ -683,15 +649,29 @@ int gigaset_isdn_register(struct cardstate *cs, const char *isdnid)
 }
 
 /**
- * gigaset_isdn_unregister() - unregister from LL
+ * gigaset_isdn_unregdev() - unregister device from LL
  * @cs:                device descriptor structure.
- *
- * Called by main module to unregister the device from the LL.
  */
-void gigaset_isdn_unregister(struct cardstate *cs)
+void gigaset_isdn_unregdev(struct cardstate *cs)
 {
        gig_dbg(DEBUG_CMD, "sending UNLOAD");
        gigaset_i4l_cmd(cs, ISDN_STAT_UNLOAD);
        kfree(cs->iif);
        cs->iif = NULL;
 }
+
+/**
+ * gigaset_isdn_regdrv() - register driver to LL
+ */
+void gigaset_isdn_regdrv(void)
+{
+       /* nothing to do */
+}
+
+/**
+ * gigaset_isdn_unregdrv() - unregister driver from LL
+ */
+void gigaset_isdn_unregdrv(void)
+{
+       /* nothing to do */
+}