diff options
author | Andrei Emeltchenko <andrei.emeltchenko@intel.com> | 2012-09-27 10:26:07 -0400 |
---|---|---|
committer | Gustavo Padovan <gustavo.padovan@collabora.co.uk> | 2012-09-27 16:10:03 -0400 |
commit | f97268fccdd4e76462195216fcab621b8d4a6cd1 (patch) | |
tree | ab9b2cebee49e3186cd80d366e6d16aeb39e2985 | |
parent | b078b564292ab87cdf4a58de3c2f86d4300a161c (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.h | 10 | ||||
-rw-r--r-- | net/bluetooth/a2mp.c | 29 |
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 | ||
22 | enum amp_mgr_state { | ||
23 | READ_LOC_AMP_INFO, | ||
24 | }; | ||
25 | |||
22 | struct amp_mgr { | 26 | struct 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 | ||
127 | extern struct list_head amp_mgr_list; | ||
128 | extern struct mutex amp_mgr_list_lock; | ||
129 | |||
121 | void amp_mgr_get(struct amp_mgr *mgr); | 130 | void amp_mgr_get(struct amp_mgr *mgr); |
122 | int amp_mgr_put(struct amp_mgr *mgr); | 131 | int amp_mgr_put(struct amp_mgr *mgr); |
123 | struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn, | 132 | struct l2cap_chan *a2mp_channel_create(struct l2cap_conn *conn, |
124 | struct sk_buff *skb); | 133 | struct sk_buff *skb); |
134 | struct 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 */ | ||
21 | LIST_HEAD(amp_mgr_list); | ||
22 | DEFINE_MUTEX(amp_mgr_list_lock); | ||
23 | |||
20 | /* A2MP build & send command helper functions */ | 24 | /* A2MP build & send command helper functions */ |
21 | static struct a2mp_cmd *__a2mp_build(u8 code, u8 ident, u16 len, void *data) | 25 | static 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(&_mgr_list_lock); | ||
524 | list_del(&mgr->list); | ||
525 | mutex_unlock(&_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(&_mgr_list_lock); | ||
564 | list_add(&mgr->list, &_mgr_list); | ||
565 | mutex_unlock(&_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 | |||
586 | struct amp_mgr *amp_mgr_lookup_by_state(u8 state) | ||
587 | { | ||
588 | struct amp_mgr *mgr; | ||
589 | |||
590 | mutex_lock(&_mgr_list_lock); | ||
591 | list_for_each_entry(mgr, &_mgr_list, list) { | ||
592 | if (mgr->state == state) { | ||
593 | amp_mgr_get(mgr); | ||
594 | mutex_unlock(&_mgr_list_lock); | ||
595 | return mgr; | ||
596 | } | ||
597 | } | ||
598 | mutex_unlock(&_mgr_list_lock); | ||
599 | |||
600 | return NULL; | ||
601 | } | ||