5 * Copyright (C) 2005-2006 Intel Corporation
6 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * FIXME: there are issues here on how BEACON and SCAN on USB RCI deal
26 * with each other. Currently seems that START_BEACON while
27 * SCAN_ONLY will cancel the scan, so we need to update the
28 * state here. Clarification request sent by email on
30 * 10/28/2005 No clear answer heard--maybe we'll hack the API
31 * so that when we start beaconing, if the HC is
32 * scanning in a mode not compatible with beaconing
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"
44 * Start/stop scanning in a radio controller
46 * @rc: UWB Radio Controller
47 * @channel: Channel to scan; encodings in WUSB1.0[Table 5.12]
48 * @type: Type of scanning to do.
49 * @bpst_offset: value at which to start scanning (if type ==
50 * UWB_SCAN_ONLY_STARTTIME)
51 * @returns: 0 if ok, < 0 errno code on error
53 * We put the command on kmalloc'ed memory as some arches cannot do
54 * USB from the stack. The reply event is copied from an stage buffer,
55 * so it can be in the stack. See WUSB1.0[8.6.2.4] for more details.
57 int uwb_rc_scan(struct uwb_rc
*rc
,
58 unsigned channel
, enum uwb_scan_type type
,
62 struct uwb_rc_cmd_scan
*cmd
;
63 struct uwb_rc_evt_confirm reply
;
66 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
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
));
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
);
88 rc
->scanning
= channel
;
91 mutex_unlock(&rc
->uwb_dev
.mutex
);
98 * Print scanning state
100 static ssize_t
uwb_rc_scan_show(struct device
*dev
,
101 struct device_attribute
*attr
, char *buf
)
103 struct uwb_dev
*uwb_dev
= to_uwb_dev(dev
);
104 struct uwb_rc
*rc
= uwb_dev
->rc
;
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
);
116 static ssize_t
uwb_rc_scan_store(struct device
*dev
,
117 struct device_attribute
*attr
,
118 const char *buf
, size_t size
)
120 struct uwb_dev
*uwb_dev
= to_uwb_dev(dev
);
121 struct uwb_rc
*rc
= uwb_dev
->rc
;
124 unsigned bpst_offset
= 0;
125 ssize_t result
= -EINVAL
;
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
);
131 return result
< 0 ? result
: size
;
134 /** Radio Control sysfs interface (declaration) */
135 DEVICE_ATTR(scan
, S_IRUGO
| S_IWUSR
, uwb_rc_scan_show
, uwb_rc_scan_store
);