beacon.c 16 KB

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