beacon.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * Ultra Wide Band
  3. * Beacon management
  4. *
  5. * Copyright (C) 2005-2006 Intel Corporation
  6. * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
  7. *
  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.
  11. *
  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.
  16. *
  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
  20. * 02110-1301, USA.
  21. *
  22. *
  23. * FIXME: docs
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/device.h>
  29. #include <linux/err.h>
  30. #include <linux/kdev_t.h>
  31. #include "uwb-internal.h"
  32. /* Start Beaconing command structure */
  33. struct uwb_rc_cmd_start_beacon {
  34. struct uwb_rccb rccb;
  35. __le16 wBPSTOffset;
  36. u8 bChannelNumber;
  37. } __attribute__((packed));
  38. static int uwb_rc_start_beacon(struct uwb_rc *rc, u16 bpst_offset, u8 channel)
  39. {
  40. int result;
  41. struct uwb_rc_cmd_start_beacon *cmd;
  42. struct uwb_rc_evt_confirm reply;
  43. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  44. if (cmd == NULL)
  45. return -ENOMEM;
  46. cmd->rccb.bCommandType = UWB_RC_CET_GENERAL;
  47. cmd->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_START_BEACON);
  48. cmd->wBPSTOffset = cpu_to_le16(bpst_offset);
  49. cmd->bChannelNumber = channel;
  50. reply.rceb.bEventType = UWB_RC_CET_GENERAL;
  51. reply.rceb.wEvent = UWB_RC_CMD_START_BEACON;
  52. result = uwb_rc_cmd(rc, "START-BEACON", &cmd->rccb, sizeof(*cmd),
  53. &reply.rceb, sizeof(reply));
  54. if (result < 0)
  55. goto error_cmd;
  56. if (reply.bResultCode != UWB_RC_RES_SUCCESS) {
  57. dev_err(&rc->uwb_dev.dev,
  58. "START-BEACON: command execution failed: %s (%d)\n",
  59. uwb_rc_strerror(reply.bResultCode), reply.bResultCode);
  60. result = -EIO;
  61. }
  62. error_cmd:
  63. kfree(cmd);
  64. return result;
  65. }
  66. static int uwb_rc_stop_beacon(struct uwb_rc *rc)
  67. {
  68. int result;
  69. struct uwb_rccb *cmd;
  70. struct uwb_rc_evt_confirm reply;
  71. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  72. if (cmd == NULL)
  73. return -ENOMEM;
  74. cmd->bCommandType = UWB_RC_CET_GENERAL;
  75. cmd->wCommand = cpu_to_le16(UWB_RC_CMD_STOP_BEACON);
  76. reply.rceb.bEventType = UWB_RC_CET_GENERAL;
  77. reply.rceb.wEvent = UWB_RC_CMD_STOP_BEACON;
  78. result = uwb_rc_cmd(rc, "STOP-BEACON", cmd, sizeof(*cmd),
  79. &reply.rceb, sizeof(reply));
  80. if (result < 0)
  81. goto error_cmd;
  82. if (reply.bResultCode != UWB_RC_RES_SUCCESS) {
  83. dev_err(&rc->uwb_dev.dev,
  84. "STOP-BEACON: command execution failed: %s (%d)\n",
  85. uwb_rc_strerror(reply.bResultCode), reply.bResultCode);
  86. result = -EIO;
  87. }
  88. error_cmd:
  89. kfree(cmd);
  90. return result;
  91. }
  92. /*
  93. * Start/stop beacons
  94. *
  95. * @rc: UWB Radio Controller to operate on
  96. * @channel: UWB channel on which to beacon (WUSB[table
  97. * 5-12]). If -1, stop beaconing.
  98. * @bpst_offset: Beacon Period Start Time offset; FIXME-do zero
  99. *
  100. * According to WHCI 0.95 [4.13.6] the driver will only receive the RCEB
  101. * of a SET IE command after the device sent the first beacon that includes
  102. * the IEs specified in the SET IE command. So, after we start beaconing we
  103. * check if there is anything in the IE cache and call the SET IE command
  104. * if needed.
  105. */
  106. int uwb_rc_beacon(struct uwb_rc *rc, int channel, unsigned bpst_offset)
  107. {
  108. int result;
  109. struct device *dev = &rc->uwb_dev.dev;
  110. if (channel < 0)
  111. channel = -1;
  112. if (channel == -1)
  113. result = uwb_rc_stop_beacon(rc);
  114. else {
  115. /* channel >= 0...dah */
  116. result = uwb_rc_start_beacon(rc, bpst_offset, channel);
  117. if (result < 0)
  118. return result;
  119. if (le16_to_cpu(rc->ies->wIELength) > 0) {
  120. result = uwb_rc_set_ie(rc, rc->ies);
  121. if (result < 0) {
  122. dev_err(dev, "Cannot set new IE on device: "
  123. "%d\n", result);
  124. result = uwb_rc_stop_beacon(rc);
  125. channel = -1;
  126. bpst_offset = 0;
  127. }
  128. }
  129. }
  130. if (result >= 0)
  131. rc->beaconing = channel;
  132. return result;
  133. }
  134. /*
  135. * Beacon cache
  136. *
  137. * The purpose of this is to speed up the lookup of becon information
  138. * when a new beacon arrives. The UWB Daemon uses it also to keep a
  139. * tab of which devices are in radio distance and which not. When a
  140. * device's beacon stays present for more than a certain amount of
  141. * time, it is considered a new, usable device. When a beacon ceases
  142. * to be received for a certain amount of time, it is considered that
  143. * the device is gone.
  144. *
  145. * FIXME: use an allocator for the entries
  146. * FIXME: use something faster for search than a list
  147. */
  148. void uwb_bce_kfree(struct kref *_bce)
  149. {
  150. struct uwb_beca_e *bce = container_of(_bce, struct uwb_beca_e, refcnt);
  151. kfree(bce->be);
  152. kfree(bce);
  153. }
  154. /* Find a beacon by dev addr in the cache */
  155. static
  156. struct uwb_beca_e *__uwb_beca_find_bydev(struct uwb_rc *rc,
  157. const struct uwb_dev_addr *dev_addr)
  158. {
  159. struct uwb_beca_e *bce, *next;
  160. list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) {
  161. if (!memcmp(&bce->dev_addr, dev_addr, sizeof(bce->dev_addr)))
  162. goto out;
  163. }
  164. bce = NULL;
  165. out:
  166. return bce;
  167. }
  168. /* Find a beacon by dev addr in the cache */
  169. static
  170. struct uwb_beca_e *__uwb_beca_find_bymac(struct uwb_rc *rc,
  171. const struct uwb_mac_addr *mac_addr)
  172. {
  173. struct uwb_beca_e *bce, *next;
  174. list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) {
  175. if (!memcmp(bce->mac_addr, mac_addr->data,
  176. sizeof(struct uwb_mac_addr)))
  177. goto out;
  178. }
  179. bce = NULL;
  180. out:
  181. return bce;
  182. }
  183. /**
  184. * uwb_dev_get_by_devaddr - get a UWB device with a specific DevAddr
  185. * @rc: the radio controller that saw the device
  186. * @devaddr: DevAddr of the UWB device to find
  187. *
  188. * There may be more than one matching device (in the case of a
  189. * DevAddr conflict), but only the first one is returned.
  190. */
  191. struct uwb_dev *uwb_dev_get_by_devaddr(struct uwb_rc *rc,
  192. const struct uwb_dev_addr *devaddr)
  193. {
  194. struct uwb_dev *found = NULL;
  195. struct uwb_beca_e *bce;
  196. mutex_lock(&rc->uwb_beca.mutex);
  197. bce = __uwb_beca_find_bydev(rc, devaddr);
  198. if (bce)
  199. found = uwb_dev_try_get(rc, bce->uwb_dev);
  200. mutex_unlock(&rc->uwb_beca.mutex);
  201. return found;
  202. }
  203. /**
  204. * uwb_dev_get_by_macaddr - get a UWB device with a specific EUI-48
  205. * @rc: the radio controller that saw the device
  206. * @devaddr: EUI-48 of the UWB device to find
  207. */
  208. struct uwb_dev *uwb_dev_get_by_macaddr(struct uwb_rc *rc,
  209. const struct uwb_mac_addr *macaddr)
  210. {
  211. struct uwb_dev *found = NULL;
  212. struct uwb_beca_e *bce;
  213. mutex_lock(&rc->uwb_beca.mutex);
  214. bce = __uwb_beca_find_bymac(rc, macaddr);
  215. if (bce)
  216. found = uwb_dev_try_get(rc, bce->uwb_dev);
  217. mutex_unlock(&rc->uwb_beca.mutex);
  218. return found;
  219. }
  220. /* Initialize a beacon cache entry */
  221. static void uwb_beca_e_init(struct uwb_beca_e *bce)
  222. {
  223. mutex_init(&bce->mutex);
  224. kref_init(&bce->refcnt);
  225. stats_init(&bce->lqe_stats);
  226. stats_init(&bce->rssi_stats);
  227. }
  228. /*
  229. * Add a beacon to the cache
  230. *
  231. * @be: Beacon event information
  232. * @bf: Beacon frame (part of b, really)
  233. * @ts_jiffies: Timestamp (in jiffies) when the beacon was received
  234. */
  235. static
  236. struct uwb_beca_e *__uwb_beca_add(struct uwb_rc *rc,
  237. struct uwb_rc_evt_beacon *be,
  238. struct uwb_beacon_frame *bf,
  239. unsigned long ts_jiffies)
  240. {
  241. struct uwb_beca_e *bce;
  242. bce = kzalloc(sizeof(*bce), GFP_KERNEL);
  243. if (bce == NULL)
  244. return NULL;
  245. uwb_beca_e_init(bce);
  246. bce->ts_jiffies = ts_jiffies;
  247. bce->uwb_dev = NULL;
  248. list_add(&bce->node, &rc->uwb_beca.list);
  249. return bce;
  250. }
  251. /*
  252. * Wipe out beacon entries that became stale
  253. *
  254. * Remove associated devicest too.
  255. */
  256. void uwb_beca_purge(struct uwb_rc *rc)
  257. {
  258. struct uwb_beca_e *bce, *next;
  259. unsigned long expires;
  260. mutex_lock(&rc->uwb_beca.mutex);
  261. list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) {
  262. expires = bce->ts_jiffies + msecs_to_jiffies(beacon_timeout_ms);
  263. if (time_after(jiffies, expires)) {
  264. uwbd_dev_offair(bce);
  265. }
  266. }
  267. mutex_unlock(&rc->uwb_beca.mutex);
  268. }
  269. /* Clean up the whole beacon cache. Called on shutdown */
  270. void uwb_beca_release(struct uwb_rc *rc)
  271. {
  272. struct uwb_beca_e *bce, *next;
  273. mutex_lock(&rc->uwb_beca.mutex);
  274. list_for_each_entry_safe(bce, next, &rc->uwb_beca.list, node) {
  275. list_del(&bce->node);
  276. uwb_bce_put(bce);
  277. }
  278. mutex_unlock(&rc->uwb_beca.mutex);
  279. }
  280. static void uwb_beacon_print(struct uwb_rc *rc, struct uwb_rc_evt_beacon *be,
  281. struct uwb_beacon_frame *bf)
  282. {
  283. char macbuf[UWB_ADDR_STRSIZE];
  284. char devbuf[UWB_ADDR_STRSIZE];
  285. char dstbuf[UWB_ADDR_STRSIZE];
  286. uwb_mac_addr_print(macbuf, sizeof(macbuf), &bf->Device_Identifier);
  287. uwb_dev_addr_print(devbuf, sizeof(devbuf), &bf->hdr.SrcAddr);
  288. uwb_dev_addr_print(dstbuf, sizeof(dstbuf), &bf->hdr.DestAddr);
  289. dev_info(&rc->uwb_dev.dev,
  290. "BEACON from %s to %s (ch%u offset %u slot %u MAC %s)\n",
  291. devbuf, dstbuf, be->bChannelNumber, be->wBPSTOffset,
  292. bf->Beacon_Slot_Number, macbuf);
  293. }
  294. /*
  295. * @bce: beacon cache entry, referenced
  296. */
  297. ssize_t uwb_bce_print_IEs(struct uwb_dev *uwb_dev, struct uwb_beca_e *bce,
  298. char *buf, size_t size)
  299. {
  300. ssize_t result = 0;
  301. struct uwb_rc_evt_beacon *be;
  302. struct uwb_beacon_frame *bf;
  303. int ies_len;
  304. struct uwb_ie_hdr *ies;
  305. mutex_lock(&bce->mutex);
  306. be = bce->be;
  307. if (be) {
  308. bf = (struct uwb_beacon_frame *)bce->be->BeaconInfo;
  309. ies_len = be->wBeaconInfoLength - sizeof(struct uwb_beacon_frame);
  310. ies = (struct uwb_ie_hdr *)bf->IEData;
  311. result = uwb_ie_dump_hex(ies, ies_len, buf, size);
  312. }
  313. mutex_unlock(&bce->mutex);
  314. return result;
  315. }
  316. /*
  317. * Verify that the beacon event, frame and IEs are ok
  318. */
  319. static int uwb_verify_beacon(struct uwb_rc *rc, struct uwb_event *evt,
  320. struct uwb_rc_evt_beacon *be)
  321. {
  322. int result = -EINVAL;
  323. struct uwb_beacon_frame *bf;
  324. struct device *dev = &rc->uwb_dev.dev;
  325. /* Is there enough data to decode a beacon frame? */
  326. if (evt->notif.size < sizeof(*be) + sizeof(*bf)) {
  327. dev_err(dev, "BEACON event: Not enough data to decode "
  328. "(%zu vs %zu bytes needed)\n", evt->notif.size,
  329. sizeof(*be) + sizeof(*bf));
  330. goto error;
  331. }
  332. /* FIXME: make sure beacon frame IEs are fine and that the whole thing
  333. * is consistent */
  334. result = 0;
  335. error:
  336. return result;
  337. }
  338. /*
  339. * Handle UWB_RC_EVT_BEACON events
  340. *
  341. * We check the beacon cache to see how the received beacon fares. If
  342. * is there already we refresh the timestamp. If not we create a new
  343. * entry.
  344. *
  345. * According to the WHCI and WUSB specs, only one beacon frame is
  346. * allowed per notification block, so we don't bother about scanning
  347. * for more.
  348. */
  349. int uwbd_evt_handle_rc_beacon(struct uwb_event *evt)
  350. {
  351. int result = -EINVAL;
  352. struct uwb_rc *rc;
  353. struct uwb_rc_evt_beacon *be;
  354. struct uwb_beacon_frame *bf;
  355. struct uwb_beca_e *bce;
  356. unsigned long last_ts;
  357. rc = evt->rc;
  358. be = container_of(evt->notif.rceb, struct uwb_rc_evt_beacon, rceb);
  359. result = uwb_verify_beacon(rc, evt, be);
  360. if (result < 0)
  361. return result;
  362. /* FIXME: handle alien beacons. */
  363. if (be->bBeaconType == UWB_RC_BEACON_TYPE_OL_ALIEN ||
  364. be->bBeaconType == UWB_RC_BEACON_TYPE_NOL_ALIEN) {
  365. return -ENOSYS;
  366. }
  367. bf = (struct uwb_beacon_frame *) be->BeaconInfo;
  368. /*
  369. * Drop beacons from devices with a NULL EUI-48 -- they cannot
  370. * be uniquely identified.
  371. *
  372. * It's expected that these will all be WUSB devices and they
  373. * have a WUSB specific connection method so ignoring them
  374. * here shouldn't be a problem.
  375. */
  376. if (uwb_mac_addr_bcast(&bf->Device_Identifier))
  377. return 0;
  378. mutex_lock(&rc->uwb_beca.mutex);
  379. bce = __uwb_beca_find_bymac(rc, &bf->Device_Identifier);
  380. if (bce == NULL) {
  381. /* Not in there, a new device is pinging */
  382. uwb_beacon_print(evt->rc, be, bf);
  383. bce = __uwb_beca_add(rc, be, bf, evt->ts_jiffies);
  384. if (bce == NULL) {
  385. mutex_unlock(&rc->uwb_beca.mutex);
  386. return -ENOMEM;
  387. }
  388. }
  389. mutex_unlock(&rc->uwb_beca.mutex);
  390. mutex_lock(&bce->mutex);
  391. /* purge old beacon data */
  392. kfree(bce->be);
  393. last_ts = bce->ts_jiffies;
  394. /* Update commonly used fields */
  395. bce->ts_jiffies = evt->ts_jiffies;
  396. bce->be = be;
  397. bce->dev_addr = bf->hdr.SrcAddr;
  398. bce->mac_addr = &bf->Device_Identifier;
  399. be->wBPSTOffset = le16_to_cpu(be->wBPSTOffset);
  400. be->wBeaconInfoLength = le16_to_cpu(be->wBeaconInfoLength);
  401. stats_add_sample(&bce->lqe_stats, be->bLQI - 7);
  402. stats_add_sample(&bce->rssi_stats, be->bRSSI + 18);
  403. /*
  404. * This might be a beacon from a new device.
  405. */
  406. if (bce->uwb_dev == NULL)
  407. uwbd_dev_onair(evt->rc, bce);
  408. mutex_unlock(&bce->mutex);
  409. return 1; /* we keep the event data */
  410. }
  411. /*
  412. * Handle UWB_RC_EVT_BEACON_SIZE events
  413. *
  414. * XXXXX
  415. */
  416. int uwbd_evt_handle_rc_beacon_size(struct uwb_event *evt)
  417. {
  418. int result = -EINVAL;
  419. struct device *dev = &evt->rc->uwb_dev.dev;
  420. struct uwb_rc_evt_beacon_size *bs;
  421. /* Is there enough data to decode the event? */
  422. if (evt->notif.size < sizeof(*bs)) {
  423. dev_err(dev, "BEACON SIZE notification: Not enough data to "
  424. "decode (%zu vs %zu bytes needed)\n",
  425. evt->notif.size, sizeof(*bs));
  426. goto error;
  427. }
  428. bs = container_of(evt->notif.rceb, struct uwb_rc_evt_beacon_size, rceb);
  429. if (0)
  430. dev_info(dev, "Beacon size changed to %u bytes "
  431. "(FIXME: action?)\n", le16_to_cpu(bs->wNewBeaconSize));
  432. else {
  433. /* temporary hack until we do something with this message... */
  434. static unsigned count;
  435. if (++count % 1000 == 0)
  436. dev_info(dev, "Beacon size changed %u times "
  437. "(FIXME: action?)\n", count);
  438. }
  439. result = 0;
  440. error:
  441. return result;
  442. }
  443. /**
  444. * uwbd_evt_handle_rc_bp_slot_change - handle a BP_SLOT_CHANGE event
  445. * @evt: the BP_SLOT_CHANGE notification from the radio controller
  446. *
  447. * If the event indicates that no beacon period slots were available
  448. * then radio controller has transitioned to a non-beaconing state.
  449. * Otherwise, simply save the current beacon slot.
  450. */
  451. int uwbd_evt_handle_rc_bp_slot_change(struct uwb_event *evt)
  452. {
  453. struct uwb_rc *rc = evt->rc;
  454. struct device *dev = &rc->uwb_dev.dev;
  455. struct uwb_rc_evt_bp_slot_change *bpsc;
  456. if (evt->notif.size < sizeof(*bpsc)) {
  457. dev_err(dev, "BP SLOT CHANGE event: Not enough data\n");
  458. return -EINVAL;
  459. }
  460. bpsc = container_of(evt->notif.rceb, struct uwb_rc_evt_bp_slot_change, rceb);
  461. mutex_lock(&rc->uwb_dev.mutex);
  462. if (uwb_rc_evt_bp_slot_change_no_slot(bpsc)) {
  463. dev_info(dev, "stopped beaconing: No free slots in BP\n");
  464. rc->beaconing = -1;
  465. } else
  466. rc->uwb_dev.beacon_slot = uwb_rc_evt_bp_slot_change_slot_num(bpsc);
  467. mutex_unlock(&rc->uwb_dev.mutex);
  468. return 0;
  469. }
  470. /**
  471. * Handle UWB_RC_EVT_BPOIE_CHANGE events
  472. *
  473. * XXXXX
  474. */
  475. struct uwb_ie_bpo {
  476. struct uwb_ie_hdr hdr;
  477. u8 bp_length;
  478. u8 data[];
  479. } __attribute__((packed));
  480. int uwbd_evt_handle_rc_bpoie_change(struct uwb_event *evt)
  481. {
  482. int result = -EINVAL;
  483. struct device *dev = &evt->rc->uwb_dev.dev;
  484. struct uwb_rc_evt_bpoie_change *bpoiec;
  485. struct uwb_ie_bpo *bpoie;
  486. static unsigned count; /* FIXME: this is a temp hack */
  487. size_t iesize;
  488. /* Is there enough data to decode it? */
  489. if (evt->notif.size < sizeof(*bpoiec)) {
  490. dev_err(dev, "BPOIEC notification: Not enough data to "
  491. "decode (%zu vs %zu bytes needed)\n",
  492. evt->notif.size, sizeof(*bpoiec));
  493. goto error;
  494. }
  495. bpoiec = container_of(evt->notif.rceb, struct uwb_rc_evt_bpoie_change, rceb);
  496. iesize = le16_to_cpu(bpoiec->wBPOIELength);
  497. if (iesize < sizeof(*bpoie)) {
  498. dev_err(dev, "BPOIEC notification: Not enough IE data to "
  499. "decode (%zu vs %zu bytes needed)\n",
  500. iesize, sizeof(*bpoie));
  501. goto error;
  502. }
  503. if (++count % 1000 == 0) /* Lame placeholder */
  504. dev_info(dev, "BPOIE: %u changes received\n", count);
  505. /*
  506. * FIXME: At this point we should go over all the IEs in the
  507. * bpoiec->BPOIE array and act on each.
  508. */
  509. result = 0;
  510. error:
  511. return result;
  512. }
  513. /*
  514. * Print beaconing state.
  515. */
  516. static ssize_t uwb_rc_beacon_show(struct device *dev,
  517. struct device_attribute *attr, char *buf)
  518. {
  519. struct uwb_dev *uwb_dev = to_uwb_dev(dev);
  520. struct uwb_rc *rc = uwb_dev->rc;
  521. ssize_t result;
  522. mutex_lock(&rc->uwb_dev.mutex);
  523. result = sprintf(buf, "%d\n", rc->beaconing);
  524. mutex_unlock(&rc->uwb_dev.mutex);
  525. return result;
  526. }
  527. /*
  528. * Start beaconing on the specified channel, or stop beaconing.
  529. */
  530. static ssize_t uwb_rc_beacon_store(struct device *dev,
  531. struct device_attribute *attr,
  532. const char *buf, size_t size)
  533. {
  534. struct uwb_dev *uwb_dev = to_uwb_dev(dev);
  535. struct uwb_rc *rc = uwb_dev->rc;
  536. int channel;
  537. ssize_t result = -EINVAL;
  538. result = sscanf(buf, "%d", &channel);
  539. if (result >= 1)
  540. result = uwb_radio_force_channel(rc, channel);
  541. return result < 0 ? result : size;
  542. }
  543. DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, uwb_rc_beacon_show, uwb_rc_beacon_store);