diff options
author | Antti Julku <antti.julku@nokia.com> | 2011-06-15 05:01:14 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-06-16 14:19:41 -0400 |
commit | b2a66aad8620337e38d6692f03d94a03d5129840 (patch) | |
tree | b12a51f45b376d0f8b1489b49c0fd17ed1497700 | |
parent | 3158c50c33c1acddcfa3c57fab812435aa459750 (diff) |
Bluetooth: Move blacklisting functions to hci_core
Move blacklisting functions to hci_core.c, so that they can
be used by both management interface and hci socket interface.
Signed-off-by: Antti Julku <antti.julku@nokia.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r-- | include/net/bluetooth/hci_core.h | 2 | ||||
-rw-r--r-- | net/bluetooth/hci_core.c | 79 | ||||
-rw-r--r-- | net/bluetooth/hci_sock.c | 70 |
3 files changed, 87 insertions, 64 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index fe05946c8f0b..26233d4d371c 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h | |||
@@ -529,6 +529,8 @@ int hci_inquiry(void __user *arg); | |||
529 | 529 | ||
530 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr); | 530 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr); |
531 | int hci_blacklist_clear(struct hci_dev *hdev); | 531 | int hci_blacklist_clear(struct hci_dev *hdev); |
532 | int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr); | ||
533 | int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr); | ||
532 | 534 | ||
533 | int hci_uuids_clear(struct hci_dev *hdev); | 535 | int hci_uuids_clear(struct hci_dev *hdev); |
534 | 536 | ||
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index f62ca1935f5a..8f5bee15e872 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -1205,6 +1205,85 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash, | |||
1205 | return 0; | 1205 | return 0; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, | ||
1209 | bdaddr_t *bdaddr) | ||
1210 | { | ||
1211 | struct list_head *p; | ||
1212 | |||
1213 | list_for_each(p, &hdev->blacklist) { | ||
1214 | struct bdaddr_list *b; | ||
1215 | |||
1216 | b = list_entry(p, struct bdaddr_list, list); | ||
1217 | |||
1218 | if (bacmp(bdaddr, &b->bdaddr) == 0) | ||
1219 | return b; | ||
1220 | } | ||
1221 | |||
1222 | return NULL; | ||
1223 | } | ||
1224 | |||
1225 | int hci_blacklist_clear(struct hci_dev *hdev) | ||
1226 | { | ||
1227 | struct list_head *p, *n; | ||
1228 | |||
1229 | list_for_each_safe(p, n, &hdev->blacklist) { | ||
1230 | struct bdaddr_list *b; | ||
1231 | |||
1232 | b = list_entry(p, struct bdaddr_list, list); | ||
1233 | |||
1234 | list_del(p); | ||
1235 | kfree(b); | ||
1236 | } | ||
1237 | |||
1238 | return 0; | ||
1239 | } | ||
1240 | |||
1241 | int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr) | ||
1242 | { | ||
1243 | struct bdaddr_list *entry; | ||
1244 | |||
1245 | hci_dev_lock(hdev); | ||
1246 | |||
1247 | if (bacmp(bdaddr, BDADDR_ANY) == 0) | ||
1248 | return -EBADF; | ||
1249 | |||
1250 | if (hci_blacklist_lookup(hdev, bdaddr)) | ||
1251 | return -EEXIST; | ||
1252 | |||
1253 | entry = kzalloc(sizeof(struct bdaddr_list), GFP_KERNEL); | ||
1254 | if (!entry) | ||
1255 | return -ENOMEM; | ||
1256 | |||
1257 | bacpy(&entry->bdaddr, bdaddr); | ||
1258 | |||
1259 | list_add(&entry->list, &hdev->blacklist); | ||
1260 | |||
1261 | hci_dev_unlock(hdev); | ||
1262 | |||
1263 | return 0; | ||
1264 | } | ||
1265 | |||
1266 | int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr) | ||
1267 | { | ||
1268 | struct bdaddr_list *entry; | ||
1269 | |||
1270 | hci_dev_lock(hdev); | ||
1271 | |||
1272 | if (bacmp(bdaddr, BDADDR_ANY) == 0) | ||
1273 | return hci_blacklist_clear(hdev); | ||
1274 | |||
1275 | entry = hci_blacklist_lookup(hdev, bdaddr); | ||
1276 | if (!entry) | ||
1277 | return -ENOENT; | ||
1278 | |||
1279 | list_del(&entry->list); | ||
1280 | kfree(entry); | ||
1281 | |||
1282 | hci_dev_unlock(hdev); | ||
1283 | |||
1284 | return 0; | ||
1285 | } | ||
1286 | |||
1208 | static void hci_clear_adv_cache(unsigned long arg) | 1287 | static void hci_clear_adv_cache(unsigned long arg) |
1209 | { | 1288 | { |
1210 | struct hci_dev *hdev = (void *) arg; | 1289 | struct hci_dev *hdev = (void *) arg; |
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 295e4a88fff8..ff02cf5e77cc 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c | |||
@@ -180,82 +180,24 @@ static int hci_sock_release(struct socket *sock) | |||
180 | return 0; | 180 | return 0; |
181 | } | 181 | } |
182 | 182 | ||
183 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr) | 183 | static int hci_sock_blacklist_add(struct hci_dev *hdev, void __user *arg) |
184 | { | ||
185 | struct list_head *p; | ||
186 | |||
187 | list_for_each(p, &hdev->blacklist) { | ||
188 | struct bdaddr_list *b; | ||
189 | |||
190 | b = list_entry(p, struct bdaddr_list, list); | ||
191 | |||
192 | if (bacmp(bdaddr, &b->bdaddr) == 0) | ||
193 | return b; | ||
194 | } | ||
195 | |||
196 | return NULL; | ||
197 | } | ||
198 | |||
199 | static int hci_blacklist_add(struct hci_dev *hdev, void __user *arg) | ||
200 | { | 184 | { |
201 | bdaddr_t bdaddr; | 185 | bdaddr_t bdaddr; |
202 | struct bdaddr_list *entry; | ||
203 | 186 | ||
204 | if (copy_from_user(&bdaddr, arg, sizeof(bdaddr))) | 187 | if (copy_from_user(&bdaddr, arg, sizeof(bdaddr))) |
205 | return -EFAULT; | 188 | return -EFAULT; |
206 | 189 | ||
207 | if (bacmp(&bdaddr, BDADDR_ANY) == 0) | 190 | return hci_blacklist_add(hdev, &bdaddr); |
208 | return -EBADF; | ||
209 | |||
210 | if (hci_blacklist_lookup(hdev, &bdaddr)) | ||
211 | return -EEXIST; | ||
212 | |||
213 | entry = kzalloc(sizeof(struct bdaddr_list), GFP_KERNEL); | ||
214 | if (!entry) | ||
215 | return -ENOMEM; | ||
216 | |||
217 | bacpy(&entry->bdaddr, &bdaddr); | ||
218 | |||
219 | list_add(&entry->list, &hdev->blacklist); | ||
220 | |||
221 | return 0; | ||
222 | } | ||
223 | |||
224 | int hci_blacklist_clear(struct hci_dev *hdev) | ||
225 | { | ||
226 | struct list_head *p, *n; | ||
227 | |||
228 | list_for_each_safe(p, n, &hdev->blacklist) { | ||
229 | struct bdaddr_list *b; | ||
230 | |||
231 | b = list_entry(p, struct bdaddr_list, list); | ||
232 | |||
233 | list_del(p); | ||
234 | kfree(b); | ||
235 | } | ||
236 | |||
237 | return 0; | ||
238 | } | 191 | } |
239 | 192 | ||
240 | static int hci_blacklist_del(struct hci_dev *hdev, void __user *arg) | 193 | static int hci_sock_blacklist_del(struct hci_dev *hdev, void __user *arg) |
241 | { | 194 | { |
242 | bdaddr_t bdaddr; | 195 | bdaddr_t bdaddr; |
243 | struct bdaddr_list *entry; | ||
244 | 196 | ||
245 | if (copy_from_user(&bdaddr, arg, sizeof(bdaddr))) | 197 | if (copy_from_user(&bdaddr, arg, sizeof(bdaddr))) |
246 | return -EFAULT; | 198 | return -EFAULT; |
247 | 199 | ||
248 | if (bacmp(&bdaddr, BDADDR_ANY) == 0) | 200 | return hci_blacklist_del(hdev, &bdaddr); |
249 | return hci_blacklist_clear(hdev); | ||
250 | |||
251 | entry = hci_blacklist_lookup(hdev, &bdaddr); | ||
252 | if (!entry) | ||
253 | return -ENOENT; | ||
254 | |||
255 | list_del(&entry->list); | ||
256 | kfree(entry); | ||
257 | |||
258 | return 0; | ||
259 | } | 201 | } |
260 | 202 | ||
261 | /* Ioctls that require bound socket */ | 203 | /* Ioctls that require bound socket */ |
@@ -290,12 +232,12 @@ static inline int hci_sock_bound_ioctl(struct sock *sk, unsigned int cmd, unsign | |||
290 | case HCIBLOCKADDR: | 232 | case HCIBLOCKADDR: |
291 | if (!capable(CAP_NET_ADMIN)) | 233 | if (!capable(CAP_NET_ADMIN)) |
292 | return -EACCES; | 234 | return -EACCES; |
293 | return hci_blacklist_add(hdev, (void __user *) arg); | 235 | return hci_sock_blacklist_add(hdev, (void __user *) arg); |
294 | 236 | ||
295 | case HCIUNBLOCKADDR: | 237 | case HCIUNBLOCKADDR: |
296 | if (!capable(CAP_NET_ADMIN)) | 238 | if (!capable(CAP_NET_ADMIN)) |
297 | return -EACCES; | 239 | return -EACCES; |
298 | return hci_blacklist_del(hdev, (void __user *) arg); | 240 | return hci_sock_blacklist_del(hdev, (void __user *) arg); |
299 | 241 | ||
300 | default: | 242 | default: |
301 | if (hdev->ioctl) | 243 | if (hdev->ioctl) |