blob: 3c241c2b3e1ac175e95f4f2be26f73b1e3bd189d [file] [log] [blame]
Andrei Emeltchenko466f8002012-05-29 13:59:01 +03001/*
2 Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved.
3 Copyright (c) 2011,2012 Intel Corp.
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 version 2 and
7 only version 2 as published by the Free Software Foundation.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13*/
14
15#include <net/bluetooth/bluetooth.h>
16#include <net/bluetooth/hci_core.h>
17#include <net/bluetooth/l2cap.h>
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030018#include <net/bluetooth/a2mp.h>
Andrei Emeltchenko466f8002012-05-29 13:59:01 +030019
20static struct l2cap_ops a2mp_chan_ops = {
21 .name = "L2CAP A2MP channel",
22};
23
24static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn)
25{
26 struct l2cap_chan *chan;
27 int err;
28
29 chan = l2cap_chan_create();
30 if (!chan)
31 return NULL;
32
33 BT_DBG("chan %p", chan);
34
35 hci_conn_hold(conn->hcon);
36
37 chan->omtu = L2CAP_A2MP_DEFAULT_MTU;
38 chan->imtu = L2CAP_A2MP_DEFAULT_MTU;
39 chan->flush_to = L2CAP_DEFAULT_FLUSH_TO;
40
41 chan->ops = &a2mp_chan_ops;
42
43 l2cap_chan_set_defaults(chan);
44 chan->remote_max_tx = chan->max_tx;
45 chan->remote_tx_win = chan->tx_win;
46
47 chan->retrans_timeout = L2CAP_DEFAULT_RETRANS_TO;
48 chan->monitor_timeout = L2CAP_DEFAULT_MONITOR_TO;
49
50 skb_queue_head_init(&chan->tx_q);
51
52 chan->mode = L2CAP_MODE_ERTM;
53
54 err = l2cap_ertm_init(chan);
55 if (err < 0) {
56 l2cap_chan_del(chan, 0);
57 return NULL;
58 }
59
60 chan->conf_state = 0;
61
62 l2cap_chan_add(conn, chan);
63
64 chan->remote_mps = chan->omtu;
65 chan->mps = chan->omtu;
66
67 chan->state = BT_CONNECTED;
68
69 return chan;
70}
Andrei Emeltchenko9740e492012-05-29 13:59:02 +030071
72/* AMP Manager functions */
73void amp_mgr_get(struct amp_mgr *mgr)
74{
75 BT_DBG("mgr %p", mgr);
76
77 kref_get(&mgr->kref);
78}
79
80static void amp_mgr_destroy(struct kref *kref)
81{
82 struct amp_mgr *mgr = container_of(kref, struct amp_mgr, kref);
83
84 BT_DBG("mgr %p", mgr);
85
86 kfree(mgr);
87}
88
89int amp_mgr_put(struct amp_mgr *mgr)
90{
91 BT_DBG("mgr %p", mgr);
92
93 return kref_put(&mgr->kref, &amp_mgr_destroy);
94}
95
96static struct amp_mgr *amp_mgr_create(struct l2cap_conn *conn)
97{
98 struct amp_mgr *mgr;
99 struct l2cap_chan *chan;
100
101 mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
102 if (!mgr)
103 return NULL;
104
105 BT_DBG("conn %p mgr %p", conn, mgr);
106
107 mgr->l2cap_conn = conn;
108
109 chan = a2mp_chan_open(conn);
110 if (!chan) {
111 kfree(mgr);
112 return NULL;
113 }
114
115 mgr->a2mp_chan = chan;
116 chan->data = mgr;
117
118 conn->hcon->amp_mgr = mgr;
119
120 kref_init(&mgr->kref);
121
122 return mgr;
123}