This source file includes following definitions.
- uwb_rc_scan
- uwb_rc_scan_show
- uwb_rc_scan_store
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/device.h>
22 #include <linux/err.h>
23 #include <linux/slab.h>
24 #include <linux/stat.h>
25 #include "uwb-internal.h"
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 int uwb_rc_scan(struct uwb_rc *rc,
43 unsigned channel, enum uwb_scan_type type,
44 unsigned bpst_offset)
45 {
46 int result;
47 struct uwb_rc_cmd_scan *cmd;
48 struct uwb_rc_evt_confirm reply;
49
50 result = -ENOMEM;
51 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
52 if (cmd == NULL)
53 goto error_kzalloc;
54 mutex_lock(&rc->uwb_dev.mutex);
55 cmd->rccb.bCommandType = UWB_RC_CET_GENERAL;
56 cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SCAN);
57 cmd->bChannelNumber = channel;
58 cmd->bScanState = type;
59 cmd->wStartTime = cpu_to_le16(bpst_offset);
60 reply.rceb.bEventType = UWB_RC_CET_GENERAL;
61 reply.rceb.wEvent = UWB_RC_CMD_SCAN;
62 result = uwb_rc_cmd(rc, "SCAN", &cmd->rccb, sizeof(*cmd),
63 &reply.rceb, sizeof(reply));
64 if (result < 0)
65 goto error_cmd;
66 if (reply.bResultCode != UWB_RC_RES_SUCCESS) {
67 dev_err(&rc->uwb_dev.dev,
68 "SCAN: command execution failed: %s (%d)\n",
69 uwb_rc_strerror(reply.bResultCode), reply.bResultCode);
70 result = -EIO;
71 goto error_cmd;
72 }
73 rc->scanning = channel;
74 rc->scan_type = type;
75 error_cmd:
76 mutex_unlock(&rc->uwb_dev.mutex);
77 kfree(cmd);
78 error_kzalloc:
79 return result;
80 }
81
82
83
84
85 static ssize_t uwb_rc_scan_show(struct device *dev,
86 struct device_attribute *attr, char *buf)
87 {
88 struct uwb_dev *uwb_dev = to_uwb_dev(dev);
89 struct uwb_rc *rc = uwb_dev->rc;
90 ssize_t result;
91
92 mutex_lock(&rc->uwb_dev.mutex);
93 result = sprintf(buf, "%d %d\n", rc->scanning, rc->scan_type);
94 mutex_unlock(&rc->uwb_dev.mutex);
95 return result;
96 }
97
98
99
100
101 static ssize_t uwb_rc_scan_store(struct device *dev,
102 struct device_attribute *attr,
103 const char *buf, size_t size)
104 {
105 struct uwb_dev *uwb_dev = to_uwb_dev(dev);
106 struct uwb_rc *rc = uwb_dev->rc;
107 unsigned channel;
108 unsigned type;
109 unsigned bpst_offset = 0;
110 ssize_t result = -EINVAL;
111
112 result = sscanf(buf, "%u %u %u\n", &channel, &type, &bpst_offset);
113 if (result >= 2 && type < UWB_SCAN_TOP)
114 result = uwb_rc_scan(rc, channel, type, bpst_offset);
115
116 return result < 0 ? result : size;
117 }
118
119
120 DEVICE_ATTR(scan, S_IRUGO | S_IWUSR, uwb_rc_scan_show, uwb_rc_scan_store);