beacon.c 17 KB

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