~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to net/bluetooth/hci_sysfs.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
static struct class *bt_class;
13
13
 
14
 
struct dentry *bt_debugfs = NULL;
 
14
struct dentry *bt_debugfs;
15
15
EXPORT_SYMBOL_GPL(bt_debugfs);
16
16
 
17
17
static inline char *link_typetostr(int type)
51
51
                                conn->features[6], conn->features[7]);
52
52
}
53
53
 
54
 
#define LINK_ATTR(_name,_mode,_show,_store) \
55
 
struct device_attribute link_attr_##_name = __ATTR(_name,_mode,_show,_store)
 
54
#define LINK_ATTR(_name, _mode, _show, _store) \
 
55
struct device_attribute link_attr_##_name = __ATTR(_name, _mode, _show, _store)
56
56
 
57
57
static LINK_ATTR(type, S_IRUGO, show_link_type, NULL);
58
58
static LINK_ATTR(address, S_IRUGO, show_link_address, NULL);
216
216
static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
217
217
{
218
218
        struct hci_dev *hdev = dev_get_drvdata(dev);
219
 
        char name[249];
 
219
        char name[HCI_MAX_NAME_LENGTH + 1];
220
220
        int i;
221
221
 
222
 
        for (i = 0; i < 248; i++)
 
222
        for (i = 0; i < HCI_MAX_NAME_LENGTH; i++)
223
223
                name[i] = hdev->dev_name[i];
224
224
 
225
 
        name[248] = '\0';
 
225
        name[HCI_MAX_NAME_LENGTH] = '\0';
226
226
        return sprintf(buf, "%s\n", name);
227
227
}
228
228
 
277
277
static ssize_t store_idle_timeout(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
278
278
{
279
279
        struct hci_dev *hdev = dev_get_drvdata(dev);
280
 
        unsigned long val;
 
280
        unsigned int val;
 
281
        int rv;
281
282
 
282
 
        if (strict_strtoul(buf, 0, &val) < 0)
283
 
                return -EINVAL;
 
283
        rv = kstrtouint(buf, 0, &val);
 
284
        if (rv < 0)
 
285
                return rv;
284
286
 
285
287
        if (val != 0 && (val < 500 || val > 3600000))
286
288
                return -EINVAL;
299
301
static ssize_t store_sniff_max_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
300
302
{
301
303
        struct hci_dev *hdev = dev_get_drvdata(dev);
302
 
        unsigned long val;
303
 
 
304
 
        if (strict_strtoul(buf, 0, &val) < 0)
305
 
                return -EINVAL;
306
 
 
307
 
        if (val < 0x0002 || val > 0xFFFE || val % 2)
308
 
                return -EINVAL;
309
 
 
310
 
        if (val < hdev->sniff_min_interval)
 
304
        u16 val;
 
305
        int rv;
 
306
 
 
307
        rv = kstrtou16(buf, 0, &val);
 
308
        if (rv < 0)
 
309
                return rv;
 
310
 
 
311
        if (val == 0 || val % 2 || val < hdev->sniff_min_interval)
311
312
                return -EINVAL;
312
313
 
313
314
        hdev->sniff_max_interval = val;
324
325
static ssize_t store_sniff_min_interval(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
325
326
{
326
327
        struct hci_dev *hdev = dev_get_drvdata(dev);
327
 
        unsigned long val;
328
 
 
329
 
        if (strict_strtoul(buf, 0, &val) < 0)
330
 
                return -EINVAL;
331
 
 
332
 
        if (val < 0x0002 || val > 0xFFFE || val % 2)
333
 
                return -EINVAL;
334
 
 
335
 
        if (val > hdev->sniff_max_interval)
 
328
        u16 val;
 
329
        int rv;
 
330
 
 
331
        rv = kstrtou16(buf, 0, &val);
 
332
        if (rv < 0)
 
333
                return rv;
 
334
 
 
335
        if (val == 0 || val % 2 || val > hdev->sniff_max_interval)
336
336
                return -EINVAL;
337
337
 
338
338
        hdev->sniff_min_interval = val;
461
461
        .llseek         = seq_lseek,
462
462
        .release        = single_release,
463
463
};
 
464
 
 
465
static void print_bt_uuid(struct seq_file *f, u8 *uuid)
 
466
{
 
467
        u32 data0, data4;
 
468
        u16 data1, data2, data3, data5;
 
469
 
 
470
        memcpy(&data0, &uuid[0], 4);
 
471
        memcpy(&data1, &uuid[4], 2);
 
472
        memcpy(&data2, &uuid[6], 2);
 
473
        memcpy(&data3, &uuid[8], 2);
 
474
        memcpy(&data4, &uuid[10], 4);
 
475
        memcpy(&data5, &uuid[14], 2);
 
476
 
 
477
        seq_printf(f, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x\n",
 
478
                                ntohl(data0), ntohs(data1), ntohs(data2),
 
479
                                ntohs(data3), ntohl(data4), ntohs(data5));
 
480
}
 
481
 
 
482
static int uuids_show(struct seq_file *f, void *p)
 
483
{
 
484
        struct hci_dev *hdev = f->private;
 
485
        struct list_head *l;
 
486
 
 
487
        hci_dev_lock_bh(hdev);
 
488
 
 
489
        list_for_each(l, &hdev->uuids) {
 
490
                struct bt_uuid *uuid;
 
491
 
 
492
                uuid = list_entry(l, struct bt_uuid, list);
 
493
 
 
494
                print_bt_uuid(f, uuid->uuid);
 
495
        }
 
496
 
 
497
        hci_dev_unlock_bh(hdev);
 
498
 
 
499
        return 0;
 
500
}
 
501
 
 
502
static int uuids_open(struct inode *inode, struct file *file)
 
503
{
 
504
        return single_open(file, uuids_show, inode->i_private);
 
505
}
 
506
 
 
507
static const struct file_operations uuids_fops = {
 
508
        .open           = uuids_open,
 
509
        .read           = seq_read,
 
510
        .llseek         = seq_lseek,
 
511
        .release        = single_release,
 
512
};
 
513
 
 
514
static int auto_accept_delay_set(void *data, u64 val)
 
515
{
 
516
        struct hci_dev *hdev = data;
 
517
 
 
518
        hci_dev_lock_bh(hdev);
 
519
 
 
520
        hdev->auto_accept_delay = val;
 
521
 
 
522
        hci_dev_unlock_bh(hdev);
 
523
 
 
524
        return 0;
 
525
}
 
526
 
 
527
static int auto_accept_delay_get(void *data, u64 *val)
 
528
{
 
529
        struct hci_dev *hdev = data;
 
530
 
 
531
        hci_dev_lock_bh(hdev);
 
532
 
 
533
        *val = hdev->auto_accept_delay;
 
534
 
 
535
        hci_dev_unlock_bh(hdev);
 
536
 
 
537
        return 0;
 
538
}
 
539
 
 
540
DEFINE_SIMPLE_ATTRIBUTE(auto_accept_delay_fops, auto_accept_delay_get,
 
541
                                        auto_accept_delay_set, "%llu\n");
 
542
 
464
543
int hci_register_sysfs(struct hci_dev *hdev)
465
544
{
466
545
        struct device *dev = &hdev->dev;
493
572
        debugfs_create_file("blacklist", 0444, hdev->debugfs,
494
573
                                                hdev, &blacklist_fops);
495
574
 
 
575
        debugfs_create_file("uuids", 0444, hdev->debugfs, hdev, &uuids_fops);
 
576
 
 
577
        debugfs_create_file("auto_accept_delay", 0444, hdev->debugfs, hdev,
 
578
                                                &auto_accept_delay_fops);
496
579
        return 0;
497
580
}
498
581