3 * modules/driver/us_interaction.c
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) Samsung Electronics, 2014
21 * 2014 Alexander Aksenov <a.aksenov@samsung.com>: Driver user<-> kernel
27 #include <linux/module.h>
28 #include <linux/skbuff.h>
29 #include <linux/types.h>
30 #include <linux/connector.h>
31 #include <linux/slab.h>
33 #include "us_interaction.h"
34 #include "us_interaction_msg.h"
35 #include "swap_driver_errors.h"
36 #include "driver_defs.h"
39 /* Connector id struct */
40 static struct cb_id cn_swap_id = {CN_SWAP_IDX, CN_SWAP_VAL};
42 /* Swap connector name */
43 static const char cn_swap_name[] = "cn_swap";
45 /* Send messages counter */
46 static u32 msg_counter = 0;
49 int us_interaction_send_msg(const void *data, size_t size)
54 msg = kzalloc(sizeof(*msg) + size, GFP_ATOMIC);
56 return -E_SD_NO_MEMORY;
58 memcpy(&msg->id, &cn_swap_id, sizeof(msg->id));
59 msg->seq = msg_counter;
61 memcpy(msg->data, data, msg->len);
63 ret = cn_netlink_send(msg, CN_DAEMON_GROUP, GFP_ATOMIC);
78 static void us_interaction_recv_msg(struct cn_msg *msg,
79 struct netlink_skb_parms *nsp)
83 int us_interaction_create(void)
87 res = cn_add_callback(&cn_swap_id, cn_swap_name, us_interaction_recv_msg);
89 return -E_SD_NL_INIT_ERR;
94 void us_interaction_destroy(void)
96 cn_del_callback(&cn_swap_id);