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