Skip to content

Commit

Permalink
Bluetooth: A2MP: Build and Send msg helpers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Andrei Emeltchenko authored and Johan Hedberg committed Jun 5, 2012
1 parent 9740e49 commit f6d3c6e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/net/bluetooth/a2mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ struct amp_mgr {
unsigned long flags;
};

struct a2mp_cmd {
__u8 code;
__u8 ident;
__le16 len;
__u8 data[0];
} __packed;

void amp_mgr_get(struct amp_mgr *mgr);
int amp_mgr_put(struct amp_mgr *mgr);

Expand Down
46 changes: 46 additions & 0 deletions net/bluetooth/a2mp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,52 @@
#include <net/bluetooth/l2cap.h>
#include <net/bluetooth/a2mp.h>

/* A2MP build & send command helper functions */
static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data)
{
struct a2mp_cmd *cmd;
int plen;

plen = sizeof(*cmd) + len;
cmd = kzalloc(plen, GFP_KERNEL);
if (!cmd)
return NULL;

cmd->code = code;
cmd->ident = ident;
cmd->len = cpu_to_le16(len);

memcpy(cmd->data, data, len);

return cmd;
}

static void a2mp_send(struct amp_mgr *mgr, u8 code, u8 ident, u16 len,
void *data)
{
struct l2cap_chan *chan = mgr->a2mp_chan;
struct a2mp_cmd *cmd;
u16 total_len = len + sizeof(*cmd);
struct kvec iv;
struct msghdr msg;

cmd = __a2mp_build(code, ident, len, data);
if (!cmd)
return;

iv.iov_base = cmd;
iv.iov_len = total_len;

memset(&msg, 0, sizeof(msg));

msg.msg_iov = (struct iovec *) &iv;
msg.msg_iovlen = 1;

l2cap_chan_send(chan, &msg, total_len, 0);

kfree(cmd);
}

static struct l2cap_ops a2mp_chan_ops = {
.name = "L2CAP A2MP channel",
};
Expand Down

0 comments on commit f6d3c6e

Please sign in to comment.