Commit | Line | Data |
---|---|---|
60c5f5fb MH |
1 | /* |
2 | BlueZ - Bluetooth protocol stack for Linux | |
3 | ||
4 | Copyright (C) 2014 Intel Corporation | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License version 2 as | |
8 | published by the Free Software Foundation; | |
9 | ||
10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | |
11 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. | |
13 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY | |
14 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES | |
15 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
16 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
17 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
18 | ||
19 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, | |
20 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS | |
21 | SOFTWARE IS DISCLAIMED. | |
22 | */ | |
23 | ||
24 | #include <linux/debugfs.h> | |
25 | ||
26 | #include <net/bluetooth/bluetooth.h> | |
27 | #include <net/bluetooth/hci_core.h> | |
28 | ||
29 | #include "hci_debugfs.h" | |
30 | ||
40ce72b1 MH |
31 | static int features_show(struct seq_file *f, void *ptr) |
32 | { | |
33 | struct hci_dev *hdev = f->private; | |
34 | u8 p; | |
35 | ||
36 | hci_dev_lock(hdev); | |
37 | for (p = 0; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { | |
38 | seq_printf(f, "%2u: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x " | |
39 | "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", p, | |
40 | hdev->features[p][0], hdev->features[p][1], | |
41 | hdev->features[p][2], hdev->features[p][3], | |
42 | hdev->features[p][4], hdev->features[p][5], | |
43 | hdev->features[p][6], hdev->features[p][7]); | |
44 | } | |
45 | if (lmp_le_capable(hdev)) | |
46 | seq_printf(f, "LE: 0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x " | |
47 | "0x%2.2x 0x%2.2x 0x%2.2x 0x%2.2x\n", | |
48 | hdev->le_features[0], hdev->le_features[1], | |
49 | hdev->le_features[2], hdev->le_features[3], | |
50 | hdev->le_features[4], hdev->le_features[5], | |
51 | hdev->le_features[6], hdev->le_features[7]); | |
52 | hci_dev_unlock(hdev); | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | static int features_open(struct inode *inode, struct file *file) | |
58 | { | |
59 | return single_open(file, features_show, inode->i_private); | |
60 | } | |
61 | ||
62 | static const struct file_operations features_fops = { | |
63 | .open = features_open, | |
64 | .read = seq_read, | |
65 | .llseek = seq_lseek, | |
66 | .release = single_release, | |
67 | }; | |
68 | ||
69 | static int device_list_show(struct seq_file *f, void *ptr) | |
70 | { | |
71 | struct hci_dev *hdev = f->private; | |
72 | struct hci_conn_params *p; | |
73 | struct bdaddr_list *b; | |
74 | ||
75 | hci_dev_lock(hdev); | |
76 | list_for_each_entry(b, &hdev->whitelist, list) | |
77 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
78 | list_for_each_entry(p, &hdev->le_conn_params, list) { | |
79 | seq_printf(f, "%pMR (type %u) %u\n", &p->addr, p->addr_type, | |
80 | p->auto_connect); | |
81 | } | |
82 | hci_dev_unlock(hdev); | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | static int device_list_open(struct inode *inode, struct file *file) | |
88 | { | |
89 | return single_open(file, device_list_show, inode->i_private); | |
90 | } | |
91 | ||
92 | static const struct file_operations device_list_fops = { | |
93 | .open = device_list_open, | |
94 | .read = seq_read, | |
95 | .llseek = seq_lseek, | |
96 | .release = single_release, | |
97 | }; | |
98 | ||
99 | static int blacklist_show(struct seq_file *f, void *p) | |
100 | { | |
101 | struct hci_dev *hdev = f->private; | |
102 | struct bdaddr_list *b; | |
103 | ||
104 | hci_dev_lock(hdev); | |
105 | list_for_each_entry(b, &hdev->blacklist, list) | |
106 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
107 | hci_dev_unlock(hdev); | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | static int blacklist_open(struct inode *inode, struct file *file) | |
113 | { | |
114 | return single_open(file, blacklist_show, inode->i_private); | |
115 | } | |
116 | ||
117 | static const struct file_operations blacklist_fops = { | |
118 | .open = blacklist_open, | |
119 | .read = seq_read, | |
120 | .llseek = seq_lseek, | |
121 | .release = single_release, | |
122 | }; | |
123 | ||
124 | static int uuids_show(struct seq_file *f, void *p) | |
125 | { | |
126 | struct hci_dev *hdev = f->private; | |
127 | struct bt_uuid *uuid; | |
128 | ||
129 | hci_dev_lock(hdev); | |
130 | list_for_each_entry(uuid, &hdev->uuids, list) { | |
131 | u8 i, val[16]; | |
132 | ||
133 | /* The Bluetooth UUID values are stored in big endian, | |
134 | * but with reversed byte order. So convert them into | |
135 | * the right order for the %pUb modifier. | |
136 | */ | |
137 | for (i = 0; i < 16; i++) | |
138 | val[i] = uuid->uuid[15 - i]; | |
139 | ||
140 | seq_printf(f, "%pUb\n", val); | |
141 | } | |
142 | hci_dev_unlock(hdev); | |
143 | ||
144 | return 0; | |
145 | } | |
146 | ||
147 | static int uuids_open(struct inode *inode, struct file *file) | |
148 | { | |
149 | return single_open(file, uuids_show, inode->i_private); | |
150 | } | |
151 | ||
152 | static const struct file_operations uuids_fops = { | |
153 | .open = uuids_open, | |
154 | .read = seq_read, | |
155 | .llseek = seq_lseek, | |
156 | .release = single_release, | |
157 | }; | |
158 | ||
159 | static int conn_info_min_age_set(void *data, u64 val) | |
160 | { | |
161 | struct hci_dev *hdev = data; | |
162 | ||
163 | if (val == 0 || val > hdev->conn_info_max_age) | |
164 | return -EINVAL; | |
165 | ||
166 | hci_dev_lock(hdev); | |
167 | hdev->conn_info_min_age = val; | |
168 | hci_dev_unlock(hdev); | |
169 | ||
170 | return 0; | |
171 | } | |
172 | ||
173 | static int conn_info_min_age_get(void *data, u64 *val) | |
174 | { | |
175 | struct hci_dev *hdev = data; | |
176 | ||
177 | hci_dev_lock(hdev); | |
178 | *val = hdev->conn_info_min_age; | |
179 | hci_dev_unlock(hdev); | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
184 | DEFINE_SIMPLE_ATTRIBUTE(conn_info_min_age_fops, conn_info_min_age_get, | |
185 | conn_info_min_age_set, "%llu\n"); | |
186 | ||
187 | static int conn_info_max_age_set(void *data, u64 val) | |
188 | { | |
189 | struct hci_dev *hdev = data; | |
190 | ||
191 | if (val == 0 || val < hdev->conn_info_min_age) | |
192 | return -EINVAL; | |
193 | ||
194 | hci_dev_lock(hdev); | |
195 | hdev->conn_info_max_age = val; | |
196 | hci_dev_unlock(hdev); | |
197 | ||
198 | return 0; | |
199 | } | |
200 | ||
201 | static int conn_info_max_age_get(void *data, u64 *val) | |
202 | { | |
203 | struct hci_dev *hdev = data; | |
204 | ||
205 | hci_dev_lock(hdev); | |
206 | *val = hdev->conn_info_max_age; | |
207 | hci_dev_unlock(hdev); | |
208 | ||
209 | return 0; | |
210 | } | |
211 | ||
212 | DEFINE_SIMPLE_ATTRIBUTE(conn_info_max_age_fops, conn_info_max_age_get, | |
213 | conn_info_max_age_set, "%llu\n"); | |
214 | ||
cb0d2fae MH |
215 | static ssize_t sc_only_mode_read(struct file *file, char __user *user_buf, |
216 | size_t count, loff_t *ppos) | |
217 | { | |
218 | struct hci_dev *hdev = file->private_data; | |
219 | char buf[3]; | |
220 | ||
221 | buf[0] = test_bit(HCI_SC_ONLY, &hdev->dev_flags) ? 'Y': 'N'; | |
222 | buf[1] = '\n'; | |
223 | buf[2] = '\0'; | |
224 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | |
225 | } | |
226 | ||
227 | static const struct file_operations sc_only_mode_fops = { | |
228 | .open = simple_open, | |
229 | .read = sc_only_mode_read, | |
230 | .llseek = default_llseek, | |
231 | }; | |
232 | ||
60c5f5fb MH |
233 | void hci_debugfs_create_common(struct hci_dev *hdev) |
234 | { | |
40ce72b1 MH |
235 | debugfs_create_file("features", 0444, hdev->debugfs, hdev, |
236 | &features_fops); | |
237 | debugfs_create_u16("manufacturer", 0444, hdev->debugfs, | |
238 | &hdev->manufacturer); | |
239 | debugfs_create_u8("hci_version", 0444, hdev->debugfs, &hdev->hci_ver); | |
240 | debugfs_create_u16("hci_revision", 0444, hdev->debugfs, &hdev->hci_rev); | |
241 | debugfs_create_file("device_list", 0444, hdev->debugfs, hdev, | |
242 | &device_list_fops); | |
243 | debugfs_create_file("blacklist", 0444, hdev->debugfs, hdev, | |
244 | &blacklist_fops); | |
245 | debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops); | |
246 | ||
247 | debugfs_create_file("conn_info_min_age", 0644, hdev->debugfs, hdev, | |
248 | &conn_info_min_age_fops); | |
249 | debugfs_create_file("conn_info_max_age", 0644, hdev->debugfs, hdev, | |
250 | &conn_info_max_age_fops); | |
cb0d2fae MH |
251 | |
252 | if (lmp_sc_capable(hdev) || lmp_le_capable(hdev)) | |
253 | debugfs_create_file("sc_only_mode", 0444, hdev->debugfs, | |
254 | hdev, &sc_only_mode_fops); | |
60c5f5fb MH |
255 | } |
256 | ||
71c3b60e MH |
257 | static int inquiry_cache_show(struct seq_file *f, void *p) |
258 | { | |
259 | struct hci_dev *hdev = f->private; | |
260 | struct discovery_state *cache = &hdev->discovery; | |
261 | struct inquiry_entry *e; | |
262 | ||
263 | hci_dev_lock(hdev); | |
264 | ||
265 | list_for_each_entry(e, &cache->all, all) { | |
266 | struct inquiry_data *data = &e->data; | |
267 | seq_printf(f, "%pMR %d %d %d 0x%.2x%.2x%.2x 0x%.4x %d %d %u\n", | |
268 | &data->bdaddr, | |
269 | data->pscan_rep_mode, data->pscan_period_mode, | |
270 | data->pscan_mode, data->dev_class[2], | |
271 | data->dev_class[1], data->dev_class[0], | |
272 | __le16_to_cpu(data->clock_offset), | |
273 | data->rssi, data->ssp_mode, e->timestamp); | |
274 | } | |
275 | ||
276 | hci_dev_unlock(hdev); | |
277 | ||
278 | return 0; | |
279 | } | |
280 | ||
281 | static int inquiry_cache_open(struct inode *inode, struct file *file) | |
282 | { | |
283 | return single_open(file, inquiry_cache_show, inode->i_private); | |
284 | } | |
285 | ||
286 | static const struct file_operations inquiry_cache_fops = { | |
287 | .open = inquiry_cache_open, | |
288 | .read = seq_read, | |
289 | .llseek = seq_lseek, | |
290 | .release = single_release, | |
291 | }; | |
292 | ||
293 | static int link_keys_show(struct seq_file *f, void *ptr) | |
294 | { | |
295 | struct hci_dev *hdev = f->private; | |
296 | struct link_key *key; | |
297 | ||
298 | rcu_read_lock(); | |
299 | list_for_each_entry_rcu(key, &hdev->link_keys, list) | |
300 | seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type, | |
301 | HCI_LINK_KEY_SIZE, key->val, key->pin_len); | |
302 | rcu_read_unlock(); | |
303 | ||
304 | return 0; | |
305 | } | |
306 | ||
307 | static int link_keys_open(struct inode *inode, struct file *file) | |
308 | { | |
309 | return single_open(file, link_keys_show, inode->i_private); | |
310 | } | |
311 | ||
312 | static const struct file_operations link_keys_fops = { | |
313 | .open = link_keys_open, | |
314 | .read = seq_read, | |
315 | .llseek = seq_lseek, | |
316 | .release = single_release, | |
317 | }; | |
318 | ||
319 | static int dev_class_show(struct seq_file *f, void *ptr) | |
320 | { | |
321 | struct hci_dev *hdev = f->private; | |
322 | ||
323 | hci_dev_lock(hdev); | |
324 | seq_printf(f, "0x%.2x%.2x%.2x\n", hdev->dev_class[2], | |
325 | hdev->dev_class[1], hdev->dev_class[0]); | |
326 | hci_dev_unlock(hdev); | |
327 | ||
328 | return 0; | |
329 | } | |
330 | ||
331 | static int dev_class_open(struct inode *inode, struct file *file) | |
332 | { | |
333 | return single_open(file, dev_class_show, inode->i_private); | |
334 | } | |
335 | ||
336 | static const struct file_operations dev_class_fops = { | |
337 | .open = dev_class_open, | |
338 | .read = seq_read, | |
339 | .llseek = seq_lseek, | |
340 | .release = single_release, | |
341 | }; | |
342 | ||
343 | static int voice_setting_get(void *data, u64 *val) | |
344 | { | |
345 | struct hci_dev *hdev = data; | |
346 | ||
347 | hci_dev_lock(hdev); | |
348 | *val = hdev->voice_setting; | |
349 | hci_dev_unlock(hdev); | |
350 | ||
351 | return 0; | |
352 | } | |
353 | ||
354 | DEFINE_SIMPLE_ATTRIBUTE(voice_setting_fops, voice_setting_get, | |
355 | NULL, "0x%4.4llx\n"); | |
356 | ||
6e07231a MH |
357 | static ssize_t ssp_debug_mode_read(struct file *file, char __user *user_buf, |
358 | size_t count, loff_t *ppos) | |
359 | { | |
360 | struct hci_dev *hdev = file->private_data; | |
361 | char buf[3]; | |
362 | ||
363 | buf[0] = hdev->ssp_debug_mode ? 'Y': 'N'; | |
364 | buf[1] = '\n'; | |
365 | buf[2] = '\0'; | |
366 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | |
367 | } | |
368 | ||
369 | static const struct file_operations ssp_debug_mode_fops = { | |
370 | .open = simple_open, | |
371 | .read = ssp_debug_mode_read, | |
372 | .llseek = default_llseek, | |
373 | }; | |
374 | ||
71c3b60e MH |
375 | static int auto_accept_delay_set(void *data, u64 val) |
376 | { | |
377 | struct hci_dev *hdev = data; | |
378 | ||
379 | hci_dev_lock(hdev); | |
380 | hdev->auto_accept_delay = val; | |
381 | hci_dev_unlock(hdev); | |
382 | ||
383 | return 0; | |
384 | } | |
385 | ||
386 | static int auto_accept_delay_get(void *data, u64 *val) | |
387 | { | |
388 | struct hci_dev *hdev = data; | |
389 | ||
390 | hci_dev_lock(hdev); | |
391 | *val = hdev->auto_accept_delay; | |
392 | hci_dev_unlock(hdev); | |
393 | ||
394 | return 0; | |
395 | } | |
396 | ||
397 | DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get, | |
398 | auto_accept_delay_set, "%llu\n"); | |
399 | ||
71c3b60e MH |
400 | static int idle_timeout_set(void *data, u64 val) |
401 | { | |
402 | struct hci_dev *hdev = data; | |
403 | ||
404 | if (val != 0 && (val < 500 || val > 3600000)) | |
405 | return -EINVAL; | |
406 | ||
407 | hci_dev_lock(hdev); | |
408 | hdev->idle_timeout = val; | |
409 | hci_dev_unlock(hdev); | |
410 | ||
411 | return 0; | |
412 | } | |
413 | ||
414 | static int idle_timeout_get(void *data, u64 *val) | |
415 | { | |
416 | struct hci_dev *hdev = data; | |
417 | ||
418 | hci_dev_lock(hdev); | |
419 | *val = hdev->idle_timeout; | |
420 | hci_dev_unlock(hdev); | |
421 | ||
422 | return 0; | |
423 | } | |
424 | ||
425 | DEFINE_SIMPLE_ATTRIBUTE(idle_timeout_fops, idle_timeout_get, | |
426 | idle_timeout_set, "%llu\n"); | |
427 | ||
428 | static int sniff_min_interval_set(void *data, u64 val) | |
429 | { | |
430 | struct hci_dev *hdev = data; | |
431 | ||
432 | if (val == 0 || val % 2 || val > hdev->sniff_max_interval) | |
433 | return -EINVAL; | |
434 | ||
435 | hci_dev_lock(hdev); | |
436 | hdev->sniff_min_interval = val; | |
437 | hci_dev_unlock(hdev); | |
438 | ||
439 | return 0; | |
440 | } | |
441 | ||
442 | static int sniff_min_interval_get(void *data, u64 *val) | |
443 | { | |
444 | struct hci_dev *hdev = data; | |
445 | ||
446 | hci_dev_lock(hdev); | |
447 | *val = hdev->sniff_min_interval; | |
448 | hci_dev_unlock(hdev); | |
449 | ||
450 | return 0; | |
451 | } | |
452 | ||
453 | DEFINE_SIMPLE_ATTRIBUTE(sniff_min_interval_fops, sniff_min_interval_get, | |
454 | sniff_min_interval_set, "%llu\n"); | |
455 | ||
456 | static int sniff_max_interval_set(void *data, u64 val) | |
457 | { | |
458 | struct hci_dev *hdev = data; | |
459 | ||
460 | if (val == 0 || val % 2 || val < hdev->sniff_min_interval) | |
461 | return -EINVAL; | |
462 | ||
463 | hci_dev_lock(hdev); | |
464 | hdev->sniff_max_interval = val; | |
465 | hci_dev_unlock(hdev); | |
466 | ||
467 | return 0; | |
468 | } | |
469 | ||
470 | static int sniff_max_interval_get(void *data, u64 *val) | |
471 | { | |
472 | struct hci_dev *hdev = data; | |
473 | ||
474 | hci_dev_lock(hdev); | |
475 | *val = hdev->sniff_max_interval; | |
476 | hci_dev_unlock(hdev); | |
477 | ||
478 | return 0; | |
479 | } | |
480 | ||
481 | DEFINE_SIMPLE_ATTRIBUTE(sniff_max_interval_fops, sniff_max_interval_get, | |
482 | sniff_max_interval_set, "%llu\n"); | |
483 | ||
60c5f5fb MH |
484 | void hci_debugfs_create_bredr(struct hci_dev *hdev) |
485 | { | |
71c3b60e MH |
486 | debugfs_create_file("inquiry_cache", 0444, hdev->debugfs, hdev, |
487 | &inquiry_cache_fops); | |
488 | debugfs_create_file("link_keys", 0400, hdev->debugfs, hdev, | |
489 | &link_keys_fops); | |
490 | debugfs_create_file("dev_class", 0444, hdev->debugfs, hdev, | |
491 | &dev_class_fops); | |
492 | debugfs_create_file("voice_setting", 0444, hdev->debugfs, hdev, | |
493 | &voice_setting_fops); | |
494 | ||
6e07231a MH |
495 | if (lmp_ssp_capable(hdev)) { |
496 | debugfs_create_file("ssp_debug_mode", 0444, hdev->debugfs, | |
497 | hdev, &ssp_debug_mode_fops); | |
71c3b60e MH |
498 | debugfs_create_file("auto_accept_delay", 0644, hdev->debugfs, |
499 | hdev, &auto_accept_delay_fops); | |
6e07231a | 500 | } |
71c3b60e MH |
501 | |
502 | if (lmp_sniff_capable(hdev)) { | |
503 | debugfs_create_file("idle_timeout", 0644, hdev->debugfs, | |
504 | hdev, &idle_timeout_fops); | |
505 | debugfs_create_file("sniff_min_interval", 0644, hdev->debugfs, | |
506 | hdev, &sniff_min_interval_fops); | |
507 | debugfs_create_file("sniff_max_interval", 0644, hdev->debugfs, | |
508 | hdev, &sniff_max_interval_fops); | |
509 | } | |
60c5f5fb MH |
510 | } |
511 | ||
3a5c82b7 MH |
512 | static int identity_show(struct seq_file *f, void *p) |
513 | { | |
514 | struct hci_dev *hdev = f->private; | |
515 | bdaddr_t addr; | |
516 | u8 addr_type; | |
517 | ||
518 | hci_dev_lock(hdev); | |
519 | ||
520 | hci_copy_identity_address(hdev, &addr, &addr_type); | |
521 | ||
522 | seq_printf(f, "%pMR (type %u) %*phN %pMR\n", &addr, addr_type, | |
523 | 16, hdev->irk, &hdev->rpa); | |
524 | ||
525 | hci_dev_unlock(hdev); | |
526 | ||
527 | return 0; | |
528 | } | |
529 | ||
530 | static int identity_open(struct inode *inode, struct file *file) | |
531 | { | |
532 | return single_open(file, identity_show, inode->i_private); | |
533 | } | |
534 | ||
535 | static const struct file_operations identity_fops = { | |
536 | .open = identity_open, | |
537 | .read = seq_read, | |
538 | .llseek = seq_lseek, | |
539 | .release = single_release, | |
540 | }; | |
541 | ||
542 | static int rpa_timeout_set(void *data, u64 val) | |
543 | { | |
544 | struct hci_dev *hdev = data; | |
545 | ||
546 | /* Require the RPA timeout to be at least 30 seconds and at most | |
547 | * 24 hours. | |
548 | */ | |
549 | if (val < 30 || val > (60 * 60 * 24)) | |
550 | return -EINVAL; | |
551 | ||
552 | hci_dev_lock(hdev); | |
553 | hdev->rpa_timeout = val; | |
554 | hci_dev_unlock(hdev); | |
555 | ||
556 | return 0; | |
557 | } | |
558 | ||
559 | static int rpa_timeout_get(void *data, u64 *val) | |
560 | { | |
561 | struct hci_dev *hdev = data; | |
562 | ||
563 | hci_dev_lock(hdev); | |
564 | *val = hdev->rpa_timeout; | |
565 | hci_dev_unlock(hdev); | |
566 | ||
567 | return 0; | |
568 | } | |
569 | ||
570 | DEFINE_SIMPLE_ATTRIBUTE(rpa_timeout_fops, rpa_timeout_get, | |
571 | rpa_timeout_set, "%llu\n"); | |
572 | ||
573 | static int random_address_show(struct seq_file *f, void *p) | |
574 | { | |
575 | struct hci_dev *hdev = f->private; | |
576 | ||
577 | hci_dev_lock(hdev); | |
578 | seq_printf(f, "%pMR\n", &hdev->random_addr); | |
579 | hci_dev_unlock(hdev); | |
580 | ||
581 | return 0; | |
582 | } | |
583 | ||
584 | static int random_address_open(struct inode *inode, struct file *file) | |
585 | { | |
586 | return single_open(file, random_address_show, inode->i_private); | |
587 | } | |
588 | ||
589 | static const struct file_operations random_address_fops = { | |
590 | .open = random_address_open, | |
591 | .read = seq_read, | |
592 | .llseek = seq_lseek, | |
593 | .release = single_release, | |
594 | }; | |
595 | ||
596 | static int static_address_show(struct seq_file *f, void *p) | |
597 | { | |
598 | struct hci_dev *hdev = f->private; | |
599 | ||
600 | hci_dev_lock(hdev); | |
601 | seq_printf(f, "%pMR\n", &hdev->static_addr); | |
602 | hci_dev_unlock(hdev); | |
603 | ||
604 | return 0; | |
605 | } | |
606 | ||
607 | static int static_address_open(struct inode *inode, struct file *file) | |
608 | { | |
609 | return single_open(file, static_address_show, inode->i_private); | |
610 | } | |
611 | ||
612 | static const struct file_operations static_address_fops = { | |
613 | .open = static_address_open, | |
614 | .read = seq_read, | |
615 | .llseek = seq_lseek, | |
616 | .release = single_release, | |
617 | }; | |
618 | ||
619 | static ssize_t force_static_address_read(struct file *file, | |
620 | char __user *user_buf, | |
621 | size_t count, loff_t *ppos) | |
622 | { | |
623 | struct hci_dev *hdev = file->private_data; | |
624 | char buf[3]; | |
625 | ||
626 | buf[0] = test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags) ? 'Y': 'N'; | |
627 | buf[1] = '\n'; | |
628 | buf[2] = '\0'; | |
629 | return simple_read_from_buffer(user_buf, count, ppos, buf, 2); | |
630 | } | |
631 | ||
632 | static ssize_t force_static_address_write(struct file *file, | |
633 | const char __user *user_buf, | |
634 | size_t count, loff_t *ppos) | |
635 | { | |
636 | struct hci_dev *hdev = file->private_data; | |
637 | char buf[32]; | |
638 | size_t buf_size = min(count, (sizeof(buf)-1)); | |
639 | bool enable; | |
640 | ||
641 | if (test_bit(HCI_UP, &hdev->flags)) | |
642 | return -EBUSY; | |
643 | ||
644 | if (copy_from_user(buf, user_buf, buf_size)) | |
645 | return -EFAULT; | |
646 | ||
647 | buf[buf_size] = '\0'; | |
648 | if (strtobool(buf, &enable)) | |
649 | return -EINVAL; | |
650 | ||
651 | if (enable == test_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags)) | |
652 | return -EALREADY; | |
653 | ||
654 | change_bit(HCI_FORCE_STATIC_ADDR, &hdev->dbg_flags); | |
655 | ||
656 | return count; | |
657 | } | |
658 | ||
659 | static const struct file_operations force_static_address_fops = { | |
660 | .open = simple_open, | |
661 | .read = force_static_address_read, | |
662 | .write = force_static_address_write, | |
663 | .llseek = default_llseek, | |
664 | }; | |
665 | ||
666 | static int white_list_show(struct seq_file *f, void *ptr) | |
667 | { | |
668 | struct hci_dev *hdev = f->private; | |
669 | struct bdaddr_list *b; | |
670 | ||
671 | hci_dev_lock(hdev); | |
672 | list_for_each_entry(b, &hdev->le_white_list, list) | |
673 | seq_printf(f, "%pMR (type %u)\n", &b->bdaddr, b->bdaddr_type); | |
674 | hci_dev_unlock(hdev); | |
675 | ||
676 | return 0; | |
677 | } | |
678 | ||
679 | static int white_list_open(struct inode *inode, struct file *file) | |
680 | { | |
681 | return single_open(file, white_list_show, inode->i_private); | |
682 | } | |
683 | ||
684 | static const struct file_operations white_list_fops = { | |
685 | .open = white_list_open, | |
686 | .read = seq_read, | |
687 | .llseek = seq_lseek, | |
688 | .release = single_release, | |
689 | }; | |
690 | ||
691 | static int identity_resolving_keys_show(struct seq_file *f, void *ptr) | |
692 | { | |
693 | struct hci_dev *hdev = f->private; | |
694 | struct smp_irk *irk; | |
695 | ||
696 | rcu_read_lock(); | |
697 | list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { | |
698 | seq_printf(f, "%pMR (type %u) %*phN %pMR\n", | |
699 | &irk->bdaddr, irk->addr_type, | |
700 | 16, irk->val, &irk->rpa); | |
701 | } | |
702 | rcu_read_unlock(); | |
703 | ||
704 | return 0; | |
705 | } | |
706 | ||
707 | static int identity_resolving_keys_open(struct inode *inode, struct file *file) | |
708 | { | |
709 | return single_open(file, identity_resolving_keys_show, | |
710 | inode->i_private); | |
711 | } | |
712 | ||
713 | static const struct file_operations identity_resolving_keys_fops = { | |
714 | .open = identity_resolving_keys_open, | |
715 | .read = seq_read, | |
716 | .llseek = seq_lseek, | |
717 | .release = single_release, | |
718 | }; | |
719 | ||
720 | static int long_term_keys_show(struct seq_file *f, void *ptr) | |
721 | { | |
722 | struct hci_dev *hdev = f->private; | |
723 | struct smp_ltk *ltk; | |
724 | ||
725 | rcu_read_lock(); | |
726 | list_for_each_entry_rcu(ltk, &hdev->long_term_keys, list) | |
727 | seq_printf(f, "%pMR (type %u) %u 0x%02x %u %.4x %.16llx %*phN\n", | |
728 | <k->bdaddr, ltk->bdaddr_type, ltk->authenticated, | |
729 | ltk->type, ltk->enc_size, __le16_to_cpu(ltk->ediv), | |
730 | __le64_to_cpu(ltk->rand), 16, ltk->val); | |
731 | rcu_read_unlock(); | |
732 | ||
733 | return 0; | |
734 | } | |
735 | ||
736 | static int long_term_keys_open(struct inode *inode, struct file *file) | |
737 | { | |
738 | return single_open(file, long_term_keys_show, inode->i_private); | |
739 | } | |
740 | ||
741 | static const struct file_operations long_term_keys_fops = { | |
742 | .open = long_term_keys_open, | |
743 | .read = seq_read, | |
744 | .llseek = seq_lseek, | |
745 | .release = single_release, | |
746 | }; | |
747 | ||
748 | static int conn_min_interval_set(void *data, u64 val) | |
749 | { | |
750 | struct hci_dev *hdev = data; | |
751 | ||
752 | if (val < 0x0006 || val > 0x0c80 || val > hdev->le_conn_max_interval) | |
753 | return -EINVAL; | |
754 | ||
755 | hci_dev_lock(hdev); | |
756 | hdev->le_conn_min_interval = val; | |
757 | hci_dev_unlock(hdev); | |
758 | ||
759 | return 0; | |
760 | } | |
761 | ||
762 | static int conn_min_interval_get(void *data, u64 *val) | |
763 | { | |
764 | struct hci_dev *hdev = data; | |
765 | ||
766 | hci_dev_lock(hdev); | |
767 | *val = hdev->le_conn_min_interval; | |
768 | hci_dev_unlock(hdev); | |
769 | ||
770 | return 0; | |
771 | } | |
772 | ||
773 | DEFINE_SIMPLE_ATTRIBUTE(conn_min_interval_fops, conn_min_interval_get, | |
774 | conn_min_interval_set, "%llu\n"); | |
775 | ||
776 | static int conn_max_interval_set(void *data, u64 val) | |
777 | { | |
778 | struct hci_dev *hdev = data; | |
779 | ||
780 | if (val < 0x0006 || val > 0x0c80 || val < hdev->le_conn_min_interval) | |
781 | return -EINVAL; | |
782 | ||
783 | hci_dev_lock(hdev); | |
784 | hdev->le_conn_max_interval = val; | |
785 | hci_dev_unlock(hdev); | |
786 | ||
787 | return 0; | |
788 | } | |
789 | ||
790 | static int conn_max_interval_get(void *data, u64 *val) | |
791 | { | |
792 | struct hci_dev *hdev = data; | |
793 | ||
794 | hci_dev_lock(hdev); | |
795 | *val = hdev->le_conn_max_interval; | |
796 | hci_dev_unlock(hdev); | |
797 | ||
798 | return 0; | |
799 | } | |
800 | ||
801 | DEFINE_SIMPLE_ATTRIBUTE(conn_max_interval_fops, conn_max_interval_get, | |
802 | conn_max_interval_set, "%llu\n"); | |
803 | ||
804 | static int conn_latency_set(void *data, u64 val) | |
805 | { | |
806 | struct hci_dev *hdev = data; | |
807 | ||
808 | if (val > 0x01f3) | |
809 | return -EINVAL; | |
810 | ||
811 | hci_dev_lock(hdev); | |
812 | hdev->le_conn_latency = val; | |
813 | hci_dev_unlock(hdev); | |
814 | ||
815 | return 0; | |
816 | } | |
817 | ||
818 | static int conn_latency_get(void *data, u64 *val) | |
819 | { | |
820 | struct hci_dev *hdev = data; | |
821 | ||
822 | hci_dev_lock(hdev); | |
823 | *val = hdev->le_conn_latency; | |
824 | hci_dev_unlock(hdev); | |
825 | ||
826 | return 0; | |
827 | } | |
828 | ||
829 | DEFINE_SIMPLE_ATTRIBUTE(conn_latency_fops, conn_latency_get, | |
830 | conn_latency_set, "%llu\n"); | |
831 | ||
832 | static int supervision_timeout_set(void *data, u64 val) | |
833 | { | |
834 | struct hci_dev *hdev = data; | |
835 | ||
836 | if (val < 0x000a || val > 0x0c80) | |
837 | return -EINVAL; | |
838 | ||
839 | hci_dev_lock(hdev); | |
840 | hdev->le_supv_timeout = val; | |
841 | hci_dev_unlock(hdev); | |
842 | ||
843 | return 0; | |
844 | } | |
845 | ||
846 | static int supervision_timeout_get(void *data, u64 *val) | |
847 | { | |
848 | struct hci_dev *hdev = data; | |
849 | ||
850 | hci_dev_lock(hdev); | |
851 | *val = hdev->le_supv_timeout; | |
852 | hci_dev_unlock(hdev); | |
853 | ||
854 | return 0; | |
855 | } | |
856 | ||
857 | DEFINE_SIMPLE_ATTRIBUTE(supervision_timeout_fops, supervision_timeout_get, | |
858 | supervision_timeout_set, "%llu\n"); | |
859 | ||
860 | static int adv_channel_map_set(void *data, u64 val) | |
861 | { | |
862 | struct hci_dev *hdev = data; | |
863 | ||
864 | if (val < 0x01 || val > 0x07) | |
865 | return -EINVAL; | |
866 | ||
867 | hci_dev_lock(hdev); | |
868 | hdev->le_adv_channel_map = val; | |
869 | hci_dev_unlock(hdev); | |
870 | ||
871 | return 0; | |
872 | } | |
873 | ||
874 | static int adv_channel_map_get(void *data, u64 *val) | |
875 | { | |
876 | struct hci_dev *hdev = data; | |
877 | ||
878 | hci_dev_lock(hdev); | |
879 | *val = hdev->le_adv_channel_map; | |
880 | hci_dev_unlock(hdev); | |
881 | ||
882 | return 0; | |
883 | } | |
884 | ||
885 | DEFINE_SIMPLE_ATTRIBUTE(adv_channel_map_fops, adv_channel_map_get, | |
886 | adv_channel_map_set, "%llu\n"); | |
887 | ||
888 | static int adv_min_interval_set(void *data, u64 val) | |
889 | { | |
890 | struct hci_dev *hdev = data; | |
891 | ||
892 | if (val < 0x0020 || val > 0x4000 || val > hdev->le_adv_max_interval) | |
893 | return -EINVAL; | |
894 | ||
895 | hci_dev_lock(hdev); | |
896 | hdev->le_adv_min_interval = val; | |
897 | hci_dev_unlock(hdev); | |
898 | ||
899 | return 0; | |
900 | } | |
901 | ||
902 | static int adv_min_interval_get(void *data, u64 *val) | |
903 | { | |
904 | struct hci_dev *hdev = data; | |
905 | ||
906 | hci_dev_lock(hdev); | |
907 | *val = hdev->le_adv_min_interval; | |
908 | hci_dev_unlock(hdev); | |
909 | ||
910 | return 0; | |
911 | } | |
912 | ||
913 | DEFINE_SIMPLE_ATTRIBUTE(adv_min_interval_fops, adv_min_interval_get, | |
914 | adv_min_interval_set, "%llu\n"); | |
915 | ||
916 | static int adv_max_interval_set(void *data, u64 val) | |
917 | { | |
918 | struct hci_dev *hdev = data; | |
919 | ||
920 | if (val < 0x0020 || val > 0x4000 || val < hdev->le_adv_min_interval) | |
921 | return -EINVAL; | |
922 | ||
923 | hci_dev_lock(hdev); | |
924 | hdev->le_adv_max_interval = val; | |
925 | hci_dev_unlock(hdev); | |
926 | ||
927 | return 0; | |
928 | } | |
929 | ||
930 | static int adv_max_interval_get(void *data, u64 *val) | |
931 | { | |
932 | struct hci_dev *hdev = data; | |
933 | ||
934 | hci_dev_lock(hdev); | |
935 | *val = hdev->le_adv_max_interval; | |
936 | hci_dev_unlock(hdev); | |
937 | ||
938 | return 0; | |
939 | } | |
940 | ||
941 | DEFINE_SIMPLE_ATTRIBUTE(adv_max_interval_fops, adv_max_interval_get, | |
942 | adv_max_interval_set, "%llu\n"); | |
943 | ||
60c5f5fb MH |
944 | void hci_debugfs_create_le(struct hci_dev *hdev) |
945 | { | |
3a5c82b7 MH |
946 | debugfs_create_file("identity", 0400, hdev->debugfs, hdev, |
947 | &identity_fops); | |
948 | debugfs_create_file("rpa_timeout", 0644, hdev->debugfs, hdev, | |
949 | &rpa_timeout_fops); | |
950 | debugfs_create_file("random_address", 0444, hdev->debugfs, hdev, | |
951 | &random_address_fops); | |
952 | debugfs_create_file("static_address", 0444, hdev->debugfs, hdev, | |
953 | &static_address_fops); | |
954 | ||
955 | /* For controllers with a public address, provide a debug | |
956 | * option to force the usage of the configured static | |
957 | * address. By default the public address is used. | |
958 | */ | |
959 | if (bacmp(&hdev->bdaddr, BDADDR_ANY)) | |
960 | debugfs_create_file("force_static_address", 0644, | |
961 | hdev->debugfs, hdev, | |
962 | &force_static_address_fops); | |
963 | ||
964 | debugfs_create_u8("white_list_size", 0444, hdev->debugfs, | |
965 | &hdev->le_white_list_size); | |
966 | debugfs_create_file("white_list", 0444, hdev->debugfs, hdev, | |
967 | &white_list_fops); | |
968 | debugfs_create_file("identity_resolving_keys", 0400, hdev->debugfs, | |
969 | hdev, &identity_resolving_keys_fops); | |
970 | debugfs_create_file("long_term_keys", 0400, hdev->debugfs, hdev, | |
971 | &long_term_keys_fops); | |
972 | debugfs_create_file("conn_min_interval", 0644, hdev->debugfs, hdev, | |
973 | &conn_min_interval_fops); | |
974 | debugfs_create_file("conn_max_interval", 0644, hdev->debugfs, hdev, | |
975 | &conn_max_interval_fops); | |
976 | debugfs_create_file("conn_latency", 0644, hdev->debugfs, hdev, | |
977 | &conn_latency_fops); | |
978 | debugfs_create_file("supervision_timeout", 0644, hdev->debugfs, hdev, | |
979 | &supervision_timeout_fops); | |
980 | debugfs_create_file("adv_channel_map", 0644, hdev->debugfs, hdev, | |
981 | &adv_channel_map_fops); | |
982 | debugfs_create_file("adv_min_interval", 0644, hdev->debugfs, hdev, | |
983 | &adv_min_interval_fops); | |
984 | debugfs_create_file("adv_max_interval", 0644, hdev->debugfs, hdev, | |
985 | &adv_max_interval_fops); | |
986 | debugfs_create_u16("discov_interleaved_timeout", 0644, hdev->debugfs, | |
987 | &hdev->discov_interleaved_timeout); | |
60c5f5fb | 988 | } |
23b9ceb7 MH |
989 | |
990 | void hci_debugfs_create_conn(struct hci_conn *conn) | |
991 | { | |
992 | struct hci_dev *hdev = conn->hdev; | |
993 | char name[6]; | |
994 | ||
995 | if (IS_ERR_OR_NULL(hdev->debugfs)) | |
996 | return; | |
997 | ||
998 | snprintf(name, sizeof(name), "%u", conn->handle); | |
999 | conn->debugfs = debugfs_create_dir(name, hdev->debugfs); | |
1000 | } |