diff options
author | Andrei Emeltchenko <andrei.emeltchenko@intel.com> | 2012-05-29 06:59:03 -0400 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@intel.com> | 2012-06-04 23:34:12 -0400 |
commit | f6d3c6e783b0e9f75b18232f8ff8cd5dbc3f7301 (patch) | |
tree | 868a752db0c703cdb9152ada0c2e3e6f276d7545 /net/bluetooth/a2mp.c | |
parent | 9740e49d17e55f3832661fd99a8e0a17e921a82e (diff) |
Bluetooth: A2MP: Build and Send msg helpers
Helper function to build and send A2MP messages.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Diffstat (limited to 'net/bluetooth/a2mp.c')
-rw-r--r-- | net/bluetooth/a2mp.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c index 3c241c2b3e1a..53f49a0b7f9a 100644 --- a/net/bluetooth/a2mp.c +++ b/net/bluetooth/a2mp.c | |||
@@ -17,6 +17,52 @@ | |||
17 | #include <net/bluetooth/l2cap.h> | 17 | #include <net/bluetooth/l2cap.h> |
18 | #include <net/bluetooth/a2mp.h> | 18 | #include <net/bluetooth/a2mp.h> |
19 | 19 | ||
20 | /* A2MP build & send command helper functions */ | ||
21 | static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data) | ||
22 | { | ||
23 | struct a2mp_cmd *cmd; | ||
24 | int plen; | ||
25 | |||
26 | plen = sizeof(*cmd) + len; | ||
27 | cmd = kzalloc(plen, GFP_KERNEL); | ||
28 | if (!cmd) | ||
29 | return NULL; | ||
30 | |||
31 | cmd->code = code; | ||
32 | cmd->ident = ident; | ||
33 | cmd->len = cpu_to_le16(len); | ||
34 | |||
35 | memcpy(cmd->data, data, len); | ||
36 | |||
37 | return cmd; | ||
38 | } | ||
39 | |||
40 | static void a2mp_send(struct amp_mgr *mgr, u8 code, u8 ident, u16 len, | ||
41 | void *data) | ||
42 | { | ||
43 | struct l2cap_chan *chan = mgr->a2mp_chan; | ||
44 | struct a2mp_cmd *cmd; | ||
45 | u16 total_len = len + sizeof(*cmd); | ||
46 | struct kvec iv; | ||
47 | struct msghdr msg; | ||
48 | |||
49 | cmd = __a2mp_build(code, ident, len, data); | ||
50 | if (!cmd) | ||
51 | return; | ||
52 | |||
53 | iv.iov_base = cmd; | ||
54 | iv.iov_len = total_len; | ||
55 | |||
56 | memset(&msg, 0, sizeof(msg)); | ||
57 | |||
58 | msg.msg_iov = (struct iovec *) &iv; | ||
59 | msg.msg_iovlen = 1; | ||
60 | |||
61 | l2cap_chan_send(chan, &msg, total_len, 0); | ||
62 | |||
63 | kfree(cmd); | ||
64 | } | ||
65 | |||
20 | static struct l2cap_ops a2mp_chan_ops = { | 66 | static struct l2cap_ops a2mp_chan_ops = { |
21 | .name = "L2CAP A2MP channel", | 67 | .name = "L2CAP A2MP channel", |
22 | }; | 68 | }; |