Messages in this thread Patch in this message | | | Subject | [5/many] acrypto: crypto_conn.c | Date | Mon, 7 Mar 2005 23:37:33 +0300 | From | Evgeniy Polyakov <> |
| |
--- /tmp/empty/crypto_conn.c 1970-01-01 03:00:00.000000000 +0300 +++ ./acrypto/crypto_conn.c 2005-03-07 21:11:01.000000000 +0300 @@ -0,0 +1,160 @@ +/* + * crypto_conn.c + * + * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru> + * + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/types.h> +#include <linux/list.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/vmalloc.h> +#include <linux/connector.h> + +#include "acrypto.h" +#include "crypto_lb.h" +#include "crypto_conn.h" +#include "crypto_user_ioctl.h" +#include "crypto_user_direct.h" + +struct cb_id crypto_conn_id = { 0xdead, 0x0000 }; +static char crypto_conn_name[] = "crconn"; + +static void crypto_conn_callback(void *data) +{ + struct cn_msg *msg, *reply; + struct crypto_conn_data *d, *cmd; + struct crypto_device *dev; + u32 sessions; + + msg = (struct cn_msg *)data; + d = (struct crypto_conn_data *)msg->data; + + if (msg->len < sizeof(*d)) { + dprintk(KERN_ERR "Wrong message to crypto connector: msg->len=%u < %u.\n", + msg->len, sizeof(*d)); + return; + } + + if (msg->len != sizeof(*d) + d->len) { + dprintk(KERN_ERR "Wrong message to crypto connector: msg->len=%u != %u.\n", + msg->len, sizeof(*d) + d->len); + return; + } + + dev = crypto_device_get_name(d->name); + if (!dev) { + dprintk(KERN_INFO "Crypto device %s was not found.\n", d->name); + return; + } + + switch (d->cmd) { + case CRYPTO_READ_SESSIONS: + reply = kmalloc(sizeof(*msg) + sizeof(*cmd) + sizeof(sessions), GFP_ATOMIC); + if (reply) { + memcpy(reply, msg, sizeof(*reply)); + reply->len = sizeof(*cmd) + sizeof(sessions); + + /* + * See protocol description in connector.c + */ + reply->ack++; + + cmd = (struct crypto_conn_data *)(reply + 1); + memcpy(cmd, d, sizeof(*cmd)); + cmd->len = sizeof(sessions); + + sessions = atomic_read(&dev->refcnt); + + memcpy(cmd + 1, &sessions, sizeof(sessions)); + + cn_netlink_send(reply, 0); + + kfree(reply); + } else + dprintk(KERN_ERR "Failed to allocate %d bytes in reply to comamnd 0x%x.\n", + sizeof(*msg) + sizeof(*cmd), d->cmd); + break; + case CRYPTO_GET_STAT: + reply = kmalloc(sizeof(*msg) + sizeof(*cmd) + sizeof(struct crypto_device_stat), GFP_ATOMIC); + if (reply) { + struct crypto_device_stat *ptr; + + memcpy(reply, msg, sizeof(*reply)); + reply->len = sizeof(*cmd) + sizeof(*ptr); + + /* + * See protocol description in connector.c + */ + reply->ack++; + + cmd = (struct crypto_conn_data *)(reply + 1); + memcpy(cmd, d, sizeof(*cmd)); + cmd->len = sizeof(*ptr); + + ptr = (struct crypto_device_stat *)(cmd + 1); + memcpy(ptr, &dev->stat, sizeof(*ptr)); + + cn_netlink_send(reply, 0); + + kfree(reply); + } else + dprintk(KERN_ERR "Failed to allocate %d bytes in reply to comamnd 0x%x.\n", + sizeof(*msg) + sizeof(*cmd), d->cmd); + break; + case CRYPTO_REQUEST: +#if 1 + { + struct crypto_user_direct *usr; + + usr = (struct crypto_user_direct *)(d->data); + + crypto_user_direct_add_request(msg->seq, msg->ack, usr); + } +#endif + break; + default: + dprintk(KERN_ERR "Wrong operation 0x%04x for crypto connector.\n", + d->cmd); + return; + } + + crypto_device_put(dev); +} + +int crypto_conn_init(void) +{ + int err; + + err = cn_add_callback(&crypto_conn_id, crypto_conn_name, crypto_conn_callback); + if (err) + return err; + + dprintk(KERN_INFO "Crypto connector callback is registered.\n"); + + return 0; +} + +void crypto_conn_fini(void) +{ + cn_del_callback(&crypto_conn_id); + dprintk(KERN_INFO "Crypto connector callback is unregistered.\n"); +} - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |