aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2012-09-27 10:26:07 -0400
committerGustavo Padovan <gustavo.padovan@collabora.co.uk>2012-09-27 16:10:03 -0400
commitf97268fccdd4e76462195216fcab621b8d4a6cd1 (patch)
treeab9b2cebee49e3186cd80d366e6d16aeb39e2985
parentb078b564292ab87cdf4a58de3c2f86d4300a161c (diff)
Bluetooth: A2MP: Create amp_mgr global list
Create amp_mgr_list global list which will be used by different hci devices to find amp_mgr. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
-rw-r--r--include/net/bluetooth/a2mp.h10
-rw-r--r--net/bluetooth/a2mp.c29
2 files changed, 39 insertions, 0 deletions
diff --git a/include/net/bluetooth/a2mp.h b/include/net/bluetooth/a2mp.h
index 6a76e0a0705e..316c1c803676 100644
--- a/include/net/bluetooth/a2mp.h
+++ b/include/net/bluetooth/a2mp.h
@@ -19,12 +19,18 @@
19 19
20#define A2MP_FEAT_EXT 0x8000 20#define A2MP_FEAT_EXT 0x8000
21 21
22enum amp_mgr_state {
23 READ_LOC_AMP_INFO,
24};
25
22struct amp_mgr { 26struct amp_mgr {
27 struct list_head list;
23 struct l2cap_conn *l2cap_conn; 28 struct l2cap_conn *l2cap_conn;
24 struct l2cap_chan *a2mp_chan; 29 struct l2cap_chan *a2mp_chan;
25 struct kref kref; 30 struct kref kref;
26 __u8 ident; 31 __u8 ident;
27 __u8 handle; 32 __u8 handle;
33 enum amp_mgr_state state;
28 unsigned long flags; 34 unsigned long flags;
29}; 35};
30 36
@@ -118,9 +124,13 @@ struct a2mp_physlink_rsp {
118#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05 124#define A2MP_STATUS_PHYS_LINK_EXISTS 0x05
119#define A2MP_STATUS_SECURITY_VIOLATION 0x06 125#define A2MP_STATUS_SECURITY_VIOLATION 0x06
120 126
127extern struct list_head amp_mgr_list;
128extern struct mutex amp_mgr_list_lock;
129
121void amp_mgr_get(struct amp_mgr *mgr); 130void amp_mgr_get(struct amp_mgr *mgr);
122int amp_mgr_put(struct amp_mgr *mgr); 131int amp_mgr_put(struct amp_mgr *mgr);
123struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn, 132struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
124 struct sk_buff *skb); 133 struct sk_buff *skb);
134struct amp_mgr *amp_mgr_lookup_by_state(u8 state);
125 135
126#endif /* __A2MP_H */ 136#endif /* __A2MP_H */
diff --git a/net/bluetooth/a2mp.c b/net/bluetooth/a2mp.c
index 0760d1fed6f0..3f930608ecfa 100644
--- a/net/bluetooth/a2mp.c
+++ b/net/bluetooth/a2mp.c
@@ -17,6 +17,10 @@
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/* Global AMP Manager list */
21LIST_HEAD(amp_mgr_list);
22DEFINE_MUTEX(amp_mgr_list_lock);
23
20/* A2MP build & send command helper functions */ 24/* A2MP build & send command helper functions */
21static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data) 25static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data)
22{ 26{
@@ -516,6 +520,10 @@ static void amp_mgr_destroy(struct kref *kref)
516 520
517 BT_DBG("mgr %p", mgr); 521 BT_DBG("mgr %p", mgr);
518 522
523 mutex_lock(&amp_mgr_list_lock);
524 list_del(&mgr->list);
525 mutex_unlock(&amp_mgr_list_lock);
526
519 kfree(mgr); 527 kfree(mgr);
520} 528}
521 529
@@ -552,6 +560,10 @@ static struct amp_mgr *amp_mgr_create(struct l2cap_conn *conn)
552 560
553 kref_init(&mgr->kref); 561 kref_init(&mgr->kref);
554 562
563 mutex_lock(&amp_mgr_list_lock);
564 list_add(&mgr->list, &amp_mgr_list);
565 mutex_unlock(&amp_mgr_list_lock);
566
555 return mgr; 567 return mgr;
556} 568}
557 569
@@ -570,3 +582,20 @@ struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn,
570 582
571 return mgr->a2mp_chan; 583 return mgr->a2mp_chan;
572} 584}
585
586struct amp_mgr *amp_mgr_lookup_by_state(u8 state)
587{
588 struct amp_mgr *mgr;
589
590 mutex_lock(&amp_mgr_list_lock);
591 list_for_each_entry(mgr, &amp_mgr_list, list) {
592 if (mgr->state == state) {
593 amp_mgr_get(mgr);
594 mutex_unlock(&amp_mgr_list_lock);
595 return mgr;
596 }
597 }
598 mutex_unlock(&amp_mgr_list_lock);
599
600 return NULL;
601}