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
35
36#include <linux/device.h>
37#include <linux/err.h>
38#include <linux/slab.h>
39#include <linux/stat.h>
40#include "uwb-internal.h"
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57int uwb_rc_scan(struct uwb_rc *rc,
58 unsigned channel, enum uwb_scan_type type,
59 unsigned bpst_offset)
60{
61 int result;
62 struct uwb_rc_cmd_scan *cmd;
63 struct uwb_rc_evt_confirm reply;
64
65 result = -ENOMEM;
66 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
67 if (cmd == NULL)
68 goto error_kzalloc;
69 mutex_lock(&rc->uwb_dev.mutex);
70 cmd->rccb.bCommandType = UWB_RC_CET_GENERAL;
71 cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SCAN);
72 cmd->bChannelNumber = channel;
73 cmd->bScanState = type;
74 cmd->wStartTime = cpu_to_le16(bpst_offset);
75 reply.rceb.bEventType = UWB_RC_CET_GENERAL;
76 reply.rceb.wEvent = UWB_RC_CMD_SCAN;
77 result = uwb_rc_cmd(rc, "SCAN", &cmd->rccb, sizeof(*cmd),
78 &reply.rceb, sizeof(reply));
79 if (result < 0)
80 goto error_cmd;
81 if (reply.bResultCode != UWB_RC_RES_SUCCESS) {
82 dev_err(&rc->uwb_dev.dev,
83 "SCAN: command execution failed: %s (%d)\n",
84 uwb_rc_strerror(reply.bResultCode), reply.bResultCode);
85 result = -EIO;
86 goto error_cmd;
87 }
88 rc->scanning = channel;
89 rc->scan_type = type;
90error_cmd:
91 mutex_unlock(&rc->uwb_dev.mutex);
92 kfree(cmd);
93error_kzalloc:
94 return result;
95}
96
97
98
99
100static ssize_t uwb_rc_scan_show(struct device *dev,
101 struct device_attribute *attr, char *buf)
102{
103 struct uwb_dev *uwb_dev = to_uwb_dev(dev);
104 struct uwb_rc *rc = uwb_dev->rc;
105 ssize_t result;
106
107 mutex_lock(&rc->uwb_dev.mutex);
108 result = sprintf(buf, "%d %d\n", rc->scanning, rc->scan_type);
109 mutex_unlock(&rc->uwb_dev.mutex);
110 return result;
111}
112
113
114
115
116static ssize_t uwb_rc_scan_store(struct device *dev,
117 struct device_attribute *attr,
118 const char *buf, size_t size)
119{
120 struct uwb_dev *uwb_dev = to_uwb_dev(dev);
121 struct uwb_rc *rc = uwb_dev->rc;
122 unsigned channel;
123 unsigned type;
124 unsigned bpst_offset = 0;
125 ssize_t result = -EINVAL;
126
127 result = sscanf(buf, "%u %u %u\n", &channel, &type, &bpst_offset);
128 if (result >= 2 && type < UWB_SCAN_TOP)
129 result = uwb_rc_scan(rc, channel, type, bpst_offset);
130
131 return result < 0 ? result : size;
132}
133
134
135DEVICE_ATTR(scan, S_IRUGO | S_IWUSR, uwb_rc_scan_show, uwb_rc_scan_store);
136