[FIX] Driver: remove duplicated file
[kernel/swap-modules.git] / driver / us_interaction.c
1 /*
2  *  SWAP device driver
3  *  modules/driver/us_interaction.c
4  *
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.
9  *
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.
14  *
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.
18  *
19  * Copyright (C) Samsung Electronics, 2014
20  *
21  * 2014  Alexander Aksenov <a.aksenov@samsung.com>: Driver user<-> kernel
22  *                                                  connect implement
23  *
24  */
25
26
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>
32
33 #include "us_interaction.h"
34 #include "us_interaction_msg.h"
35 #include "swap_driver_errors.h"
36 #include "driver_defs.h"
37
38
39 /* Connector id struct */
40 static struct cb_id cn_swap_id = {CN_SWAP_IDX, CN_SWAP_VAL};
41
42 /* Swap connector name */
43 static const char cn_swap_name[] = "cn_swap";
44
45 /* Send messages counter */
46 static u32 msg_counter = 0;
47
48
49 int us_interaction_send_msg(const void *data, size_t size)
50 {
51         struct cn_msg *msg;
52         int ret;
53
54         msg = kzalloc(sizeof(*msg) + size, GFP_ATOMIC);
55         if (msg == NULL)
56                 return -E_SD_NO_MEMORY;
57
58         memcpy(&msg->id, &cn_swap_id, sizeof(msg->id));
59         msg->seq = msg_counter;
60         msg->len = size;
61         memcpy(msg->data, data, msg->len);
62
63         ret = cn_netlink_send(msg, CN_DAEMON_GROUP, GFP_ATOMIC);
64         if (ret < 0)
65                 goto fail_send;
66         kfree(msg);
67
68         msg_counter++;
69
70         return E_SD_SUCCESS;
71
72 fail_send:
73         kfree(msg);
74
75         return ret;
76 }
77
78 static void us_interaction_recv_msg(struct cn_msg *msg,
79                                     struct netlink_skb_parms *nsp)
80 {
81 }
82
83 int us_interaction_create(void)
84 {
85         int res;
86
87         res = cn_add_callback(&cn_swap_id, cn_swap_name, us_interaction_recv_msg);
88         if (res)
89                 return -E_SD_NL_INIT_ERR;
90
91         return E_SD_SUCCESS;
92 }
93
94 void us_interaction_destroy(void)
95 {
96         cn_del_callback(&cn_swap_id);
97 }