This source file includes following definitions.
- hci_route_lookup
- hci_memo_find
- hci_memo_free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 #include <sys/cdefs.h>
35
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/malloc.h>
39 #include <sys/mbuf.h>
40 #include <sys/proc.h>
41 #include <sys/queue.h>
42 #include <sys/systm.h>
43
44 #include <netbt/bluetooth.h>
45 #include <netbt/hci.h>
46
47
48
49
50
51 int hci_memo_expiry = 600;
52
53
54
55
56 int
57 hci_route_lookup(bdaddr_t *src, bdaddr_t *dest)
58 {
59 struct hci_unit *unit;
60 struct hci_link *link;
61 struct hci_memo *memo;
62
63
64
65
66
67 TAILQ_FOREACH(unit, &hci_unit_list, hci_next) {
68 if ((unit->hci_flags & BTF_UP) == 0)
69 continue;
70
71 TAILQ_FOREACH(link, &unit->hci_links, hl_next) {
72 if (link->hl_type != HCI_LINK_ACL)
73 continue;
74
75 if (bdaddr_same(&link->hl_bdaddr, dest))
76 goto found;
77 }
78 }
79
80
81
82
83
84 TAILQ_FOREACH(unit, &hci_unit_list, hci_next) {
85 if ((unit->hci_flags & BTF_UP) == 0)
86 continue;
87
88 memo = hci_memo_find(unit, dest);
89 if (memo)
90 goto found;
91 }
92
93
94
95
96
97 TAILQ_FOREACH(unit, &hci_unit_list, hci_next) {
98 if ((unit->hci_flags & BTF_UP) == 0)
99 continue;
100
101 goto found;
102 }
103
104 return EHOSTUNREACH;
105
106 found:
107 bdaddr_copy(src, &unit->hci_bdaddr);
108 return 0;
109 }
110
111
112
113
114 struct hci_memo *
115 hci_memo_find(struct hci_unit *unit, bdaddr_t *bdaddr)
116 {
117 struct hci_memo *memo, *m0;
118 struct timeval now;
119
120 microtime(&now);
121
122 m0 = LIST_FIRST(&unit->hci_memos);
123 while ((memo = m0) != NULL) {
124 m0 = LIST_NEXT(memo, next);
125
126 if (now.tv_sec > memo->time.tv_sec + hci_memo_expiry) {
127 DPRINTF("memo %p too old (expiring)\n", memo);
128 hci_memo_free(memo);
129 continue;
130 }
131
132 if (bdaddr_same(bdaddr, &memo->response.bdaddr)) {
133 DPRINTF("memo %p found\n", memo);
134 return memo;
135 }
136 }
137
138 DPRINTF("no memo found\n");
139 return NULL;
140 }
141
142 void
143 hci_memo_free(struct hci_memo *memo)
144 {
145
146 LIST_REMOVE(memo, next);
147 free(memo, M_BLUETOOTH);
148 }