diff options
author | Andrei Emeltchenko <andrei.emeltchenko@intel.com> | 2012-09-27 10:26:12 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.co.uk> | 2012-09-27 16:12:46 -0400 |
commit | 52c0d6e56b634b195e377192182391d526cdd5e4 (patch) | |
tree | 24a32bc650f821d9aeadf90c7891285f50778774 /net/bluetooth | |
parent | 3161ae1c72f03b021bc67504c13025626c26d30c (diff) |
Bluetooth: AMP: Remote AMP ctrl definitions
Create remote AMP controllers structure. It is used to keep information
about discovered remote AMP controllers by A2MP protocol.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Diffstat (limited to 'net/bluetooth')
-rw-r--r-- | net/bluetooth/a2mp.c | 5 | ||||
-rw-r--r-- | net/bluetooth/amp.c | 79 |
2 files changed, 84 insertions, 0 deletions
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c index f04c44146663..35e188c7a441 100644 --- a/net/bluetooth/a2mp.c +++ b/net/bluetooth/a2mp.c | |||
@@ -594,6 +594,7 @@ static void amp_mgr_destroy(struct kref *kref) | |||
594 | list_del(&mgr->list); | 594 | list_del(&mgr->list); |
595 | mutex_unlock(&_mgr_list_lock); | 595 | mutex_unlock(&_mgr_list_lock); |
596 | 596 | ||
597 | amp_ctrl_list_flush(mgr); | ||
597 | kfree(mgr); | 598 | kfree(mgr); |
598 | } | 599 | } |
599 | 600 | ||
@@ -630,6 +631,10 @@ static struct amp_mgr *amp_mgr_create(struct l2cap_conn *conn) | |||
630 | 631 | ||
631 | kref_init(&mgr->kref); | 632 | kref_init(&mgr->kref); |
632 | 633 | ||
634 | /* Remote AMP ctrl list initialization */ | ||
635 | INIT_LIST_HEAD(&mgr->amp_ctrls); | ||
636 | mutex_init(&mgr->amp_ctrls_lock); | ||
637 | |||
633 | mutex_lock(&_mgr_list_lock); | 638 | mutex_lock(&_mgr_list_lock); |
634 | list_add(&mgr->list, &_mgr_list); | 639 | list_add(&mgr->list, &_mgr_list); |
635 | mutex_unlock(&_mgr_list_lock); | 640 | mutex_unlock(&_mgr_list_lock); |
diff --git a/net/bluetooth/amp.c b/net/bluetooth/amp.c index 50a7b2fb8bf3..8ef912c36224 100644 --- a/net/bluetooth/amp.c +++ b/net/bluetooth/amp.c | |||
@@ -17,6 +17,85 @@ | |||
17 | #include <net/bluetooth/a2mp.h> | 17 | #include <net/bluetooth/a2mp.h> |
18 | #include <net/bluetooth/amp.h> | 18 | #include <net/bluetooth/amp.h> |
19 | 19 | ||
20 | /* Remote AMP Controllers interface */ | ||
21 | static void amp_ctrl_get(struct amp_ctrl *ctrl) | ||
22 | { | ||
23 | BT_DBG("ctrl %p orig refcnt %d", ctrl, | ||
24 | atomic_read(&ctrl->kref.refcount)); | ||
25 | |||
26 | kref_get(&ctrl->kref); | ||
27 | } | ||
28 | |||
29 | static void amp_ctrl_destroy(struct kref *kref) | ||
30 | { | ||
31 | struct amp_ctrl *ctrl = container_of(kref, struct amp_ctrl, kref); | ||
32 | |||
33 | BT_DBG("ctrl %p", ctrl); | ||
34 | |||
35 | kfree(ctrl->assoc); | ||
36 | kfree(ctrl); | ||
37 | } | ||
38 | |||
39 | int amp_ctrl_put(struct amp_ctrl *ctrl) | ||
40 | { | ||
41 | BT_DBG("ctrl %p orig refcnt %d", ctrl, | ||
42 | atomic_read(&ctrl->kref.refcount)); | ||
43 | |||
44 | return kref_put(&ctrl->kref, &_ctrl_destroy); | ||
45 | } | ||
46 | |||
47 | struct amp_ctrl *amp_ctrl_add(struct amp_mgr *mgr) | ||
48 | { | ||
49 | struct amp_ctrl *ctrl; | ||
50 | |||
51 | ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); | ||
52 | if (!ctrl) | ||
53 | return NULL; | ||
54 | |||
55 | mutex_lock(&mgr->amp_ctrls_lock); | ||
56 | list_add(&ctrl->list, &mgr->amp_ctrls); | ||
57 | mutex_unlock(&mgr->amp_ctrls_lock); | ||
58 | |||
59 | kref_init(&ctrl->kref); | ||
60 | |||
61 | BT_DBG("mgr %p ctrl %p", mgr, ctrl); | ||
62 | |||
63 | return ctrl; | ||
64 | } | ||
65 | |||
66 | void amp_ctrl_list_flush(struct amp_mgr *mgr) | ||
67 | { | ||
68 | struct amp_ctrl *ctrl, *n; | ||
69 | |||
70 | BT_DBG("mgr %p", mgr); | ||
71 | |||
72 | mutex_lock(&mgr->amp_ctrls_lock); | ||
73 | list_for_each_entry_safe(ctrl, n, &mgr->amp_ctrls, list) { | ||
74 | list_del(&ctrl->list); | ||
75 | amp_ctrl_put(ctrl); | ||
76 | } | ||
77 | mutex_unlock(&mgr->amp_ctrls_lock); | ||
78 | } | ||
79 | |||
80 | struct amp_ctrl *amp_ctrl_lookup(struct amp_mgr *mgr, u8 id) | ||
81 | { | ||
82 | struct amp_ctrl *ctrl; | ||
83 | |||
84 | BT_DBG("mgr %p id %d", mgr, id); | ||
85 | |||
86 | mutex_lock(&mgr->amp_ctrls_lock); | ||
87 | list_for_each_entry(ctrl, &mgr->amp_ctrls, list) { | ||
88 | if (ctrl->id == id) { | ||
89 | amp_ctrl_get(ctrl); | ||
90 | mutex_unlock(&mgr->amp_ctrls_lock); | ||
91 | return ctrl; | ||
92 | } | ||
93 | } | ||
94 | mutex_unlock(&mgr->amp_ctrls_lock); | ||
95 | |||
96 | return NULL; | ||
97 | } | ||
98 | |||
20 | /* Physical Link interface */ | 99 | /* Physical Link interface */ |
21 | static u8 __next_handle(struct amp_mgr *mgr) | 100 | static u8 __next_handle(struct amp_mgr *mgr) |
22 | { | 101 | { |