devconnect.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. /*
  2. * WUSB Wire Adapter: Control/Data Streaming Interface (WUSB[8])
  3. * Device Connect handling
  4. *
  5. * Copyright (C) 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. * FIXME: this file needs to be broken up, it's grown too big
  25. *
  26. *
  27. * WUSB1.0[7.1, 7.5.1, ]
  28. *
  29. * WUSB device connection is kind of messy. Some background:
  30. *
  31. * When a device wants to connect it scans the UWB radio channels
  32. * looking for a WUSB Channel; a WUSB channel is defined by MMCs
  33. * (Micro Managed Commands or something like that) [see
  34. * Design-overview for more on this] .
  35. *
  36. * So, device scans the radio, finds MMCs and thus a host and checks
  37. * when the next DNTS is. It sends a Device Notification Connect
  38. * (DN_Connect); the host picks it up (through nep.c and notif.c, ends
  39. * up in wusb_devconnect_ack(), which creates a wusb_dev structure in
  40. * wusbhc->port[port_number].wusb_dev), assigns an unauth address
  41. * to the device (this means from 0x80 to 0xfe) and sends, in the MMC
  42. * a Connect Ack Information Element (ConnAck IE).
  43. *
  44. * So now the device now has a WUSB address. From now on, we use
  45. * that to talk to it in the RPipes.
  46. *
  47. * ASSUMPTIONS:
  48. *
  49. * - We use the the as device address the port number where it is
  50. * connected (port 0 doesn't exist). For unauth, it is 128 + that.
  51. *
  52. * ROADMAP:
  53. *
  54. * This file contains the logic for doing that--entry points:
  55. *
  56. * wusb_devconnect_ack() Ack a device until _acked() called.
  57. * Called by notif.c:wusb_handle_dn_connect()
  58. * when a DN_Connect is received.
  59. *
  60. * wusb_devconnect_acked() Ack done, release resources.
  61. *
  62. * wusb_handle_dn_alive() Called by notif.c:wusb_handle_dn()
  63. * for processing a DN_Alive pong from a device.
  64. *
  65. * wusb_handle_dn_disconnect()Called by notif.c:wusb_handle_dn() to
  66. * process a disconenct request from a
  67. * device.
  68. *
  69. * __wusb_dev_disable() Called by rh.c:wusbhc_rh_clear_port_feat() when
  70. * disabling a port.
  71. *
  72. * wusb_devconnect_create() Called when creating the host by
  73. * lc.c:wusbhc_create().
  74. *
  75. * wusb_devconnect_destroy() Cleanup called removing the host. Called
  76. * by lc.c:wusbhc_destroy().
  77. *
  78. * Each Wireless USB host maintains a list of DN_Connect requests
  79. * (actually we maintain a list of pending Connect Acks, the
  80. * wusbhc->ca_list).
  81. *
  82. * LIFE CYCLE OF port->wusb_dev
  83. *
  84. * Before the @wusbhc structure put()s the reference it owns for
  85. * port->wusb_dev [and clean the wusb_dev pointer], it needs to
  86. * lock @wusbhc->mutex.
  87. */
  88. #include <linux/jiffies.h>
  89. #include <linux/ctype.h>
  90. #include <linux/workqueue.h>
  91. #include "wusbhc.h"
  92. static void wusbhc_devconnect_acked_work(struct work_struct *work);
  93. static void wusb_dev_free(struct wusb_dev *wusb_dev)
  94. {
  95. if (wusb_dev) {
  96. kfree(wusb_dev->set_gtk_req);
  97. usb_free_urb(wusb_dev->set_gtk_urb);
  98. kfree(wusb_dev);
  99. }
  100. }
  101. static struct wusb_dev *wusb_dev_alloc(struct wusbhc *wusbhc)
  102. {
  103. struct wusb_dev *wusb_dev;
  104. struct urb *urb;
  105. struct usb_ctrlrequest *req;
  106. wusb_dev = kzalloc(sizeof(*wusb_dev), GFP_KERNEL);
  107. if (wusb_dev == NULL)
  108. goto err;
  109. wusb_dev->wusbhc = wusbhc;
  110. INIT_WORK(&wusb_dev->devconnect_acked_work, wusbhc_devconnect_acked_work);
  111. urb = usb_alloc_urb(0, GFP_KERNEL);
  112. if (urb == NULL)
  113. goto err;
  114. req = kmalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
  115. if (req == NULL)
  116. goto err;
  117. req->bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;
  118. req->bRequest = USB_REQ_SET_DESCRIPTOR;
  119. req->wValue = cpu_to_le16(USB_DT_KEY << 8 | wusbhc->gtk_index);
  120. req->wIndex = 0;
  121. req->wLength = cpu_to_le16(wusbhc->gtk.descr.bLength);
  122. wusb_dev->set_gtk_urb = urb;
  123. wusb_dev->set_gtk_req = req;
  124. return wusb_dev;
  125. err:
  126. wusb_dev_free(wusb_dev);
  127. return NULL;
  128. }
  129. /*
  130. * Using the Connect-Ack list, fill out the @wusbhc Connect-Ack WUSB IE
  131. * properly so that it can be added to the MMC.
  132. *
  133. * We just get the @wusbhc->ca_list and fill out the first four ones or
  134. * less (per-spec WUSB1.0[7.5, before T7-38). If the ConnectAck WUSB
  135. * IE is not allocated, we alloc it.
  136. *
  137. * @wusbhc->mutex must be taken
  138. */
  139. static void wusbhc_fill_cack_ie(struct wusbhc *wusbhc)
  140. {
  141. unsigned cnt;
  142. struct wusb_dev *dev_itr;
  143. struct wuie_connect_ack *cack_ie;
  144. cack_ie = &wusbhc->cack_ie;
  145. cnt = 0;
  146. list_for_each_entry(dev_itr, &wusbhc->cack_list, cack_node) {
  147. cack_ie->blk[cnt].CDID = dev_itr->cdid;
  148. cack_ie->blk[cnt].bDeviceAddress = dev_itr->addr;
  149. if (++cnt >= WUIE_ELT_MAX)
  150. break;
  151. }
  152. cack_ie->hdr.bLength = sizeof(cack_ie->hdr)
  153. + cnt * sizeof(cack_ie->blk[0]);
  154. }
  155. /*
  156. * Register a new device that wants to connect
  157. *
  158. * A new device wants to connect, so we add it to the Connect-Ack
  159. * list. We give it an address in the unauthorized range (bit 8 set);
  160. * user space will have to drive authorization further on.
  161. *
  162. * @dev_addr: address to use for the device (which is also the port
  163. * number).
  164. *
  165. * @wusbhc->mutex must be taken
  166. */
  167. static struct wusb_dev *wusbhc_cack_add(struct wusbhc *wusbhc,
  168. struct wusb_dn_connect *dnc,
  169. const char *pr_cdid, u8 port_idx)
  170. {
  171. struct device *dev = wusbhc->dev;
  172. struct wusb_dev *wusb_dev;
  173. int new_connection = wusb_dn_connect_new_connection(dnc);
  174. u8 dev_addr;
  175. int result;
  176. /* Is it registered already? */
  177. list_for_each_entry(wusb_dev, &wusbhc->cack_list, cack_node)
  178. if (!memcmp(&wusb_dev->cdid, &dnc->CDID,
  179. sizeof(wusb_dev->cdid)))
  180. return wusb_dev;
  181. /* We don't have it, create an entry, register it */
  182. wusb_dev = wusb_dev_alloc(wusbhc);
  183. if (wusb_dev == NULL)
  184. return NULL;
  185. wusb_dev_init(wusb_dev);
  186. wusb_dev->cdid = dnc->CDID;
  187. wusb_dev->port_idx = port_idx;
  188. /*
  189. * Devices are always available within the cluster reservation
  190. * and since the hardware will take the intersection of the
  191. * per-device availability and the cluster reservation, the
  192. * per-device availability can simply be set to always
  193. * available.
  194. */
  195. bitmap_fill(wusb_dev->availability.bm, UWB_NUM_MAS);
  196. /* FIXME: handle reconnects instead of assuming connects are
  197. always new. */
  198. if (1 && new_connection == 0)
  199. new_connection = 1;
  200. if (new_connection) {
  201. dev_addr = (port_idx + 2) | WUSB_DEV_ADDR_UNAUTH;
  202. dev_info(dev, "Connecting new WUSB device to address %u, "
  203. "port %u\n", dev_addr, port_idx);
  204. result = wusb_set_dev_addr(wusbhc, wusb_dev, dev_addr);
  205. if (result < 0)
  206. return NULL;
  207. }
  208. wusb_dev->entry_ts = jiffies;
  209. list_add_tail(&wusb_dev->cack_node, &wusbhc->cack_list);
  210. wusbhc->cack_count++;
  211. wusbhc_fill_cack_ie(wusbhc);
  212. return wusb_dev;
  213. }
  214. /*
  215. * Remove a Connect-Ack context entry from the HCs view
  216. *
  217. * @wusbhc->mutex must be taken
  218. */
  219. static void wusbhc_cack_rm(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  220. {
  221. list_del_init(&wusb_dev->cack_node);
  222. wusbhc->cack_count--;
  223. wusbhc_fill_cack_ie(wusbhc);
  224. }
  225. /*
  226. * @wusbhc->mutex must be taken */
  227. static
  228. void wusbhc_devconnect_acked(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  229. {
  230. wusbhc_cack_rm(wusbhc, wusb_dev);
  231. if (wusbhc->cack_count)
  232. wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr);
  233. else
  234. wusbhc_mmcie_rm(wusbhc, &wusbhc->cack_ie.hdr);
  235. }
  236. static void wusbhc_devconnect_acked_work(struct work_struct *work)
  237. {
  238. struct wusb_dev *wusb_dev = container_of(work, struct wusb_dev,
  239. devconnect_acked_work);
  240. struct wusbhc *wusbhc = wusb_dev->wusbhc;
  241. mutex_lock(&wusbhc->mutex);
  242. wusbhc_devconnect_acked(wusbhc, wusb_dev);
  243. mutex_unlock(&wusbhc->mutex);
  244. }
  245. /*
  246. * Ack a device for connection
  247. *
  248. * FIXME: docs
  249. *
  250. * @pr_cdid: Printable CDID...hex Use @dnc->cdid for the real deal.
  251. *
  252. * So we get the connect ack IE (may have been allocated already),
  253. * find an empty connect block, an empty virtual port, create an
  254. * address with it (see below), make it an unauth addr [bit 7 set] and
  255. * set the MMC.
  256. *
  257. * Addresses: because WUSB hosts have no downstream hubs, we can do a
  258. * 1:1 mapping between 'port number' and device
  259. * address. This simplifies many things, as during this
  260. * initial connect phase the USB stack has no knoledge of
  261. * the device and hasn't assigned an address yet--we know
  262. * USB's choose_address() will use the same euristics we
  263. * use here, so we can assume which address will be assigned.
  264. *
  265. * USB stack always assigns address 1 to the root hub, so
  266. * to the port number we add 2 (thus virtual port #0 is
  267. * addr #2).
  268. *
  269. * @wusbhc shall be referenced
  270. */
  271. static
  272. void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc,
  273. const char *pr_cdid)
  274. {
  275. int result;
  276. struct device *dev = wusbhc->dev;
  277. struct wusb_dev *wusb_dev;
  278. struct wusb_port *port;
  279. unsigned idx, devnum;
  280. mutex_lock(&wusbhc->mutex);
  281. /* Check we are not handling it already */
  282. for (idx = 0; idx < wusbhc->ports_max; idx++) {
  283. port = wusb_port_by_idx(wusbhc, idx);
  284. if (port->wusb_dev
  285. && memcmp(&dnc->CDID, &port->wusb_dev->cdid, sizeof(dnc->CDID)) == 0)
  286. goto error_unlock;
  287. }
  288. /* Look up those fake ports we have for a free one */
  289. for (idx = 0; idx < wusbhc->ports_max; idx++) {
  290. port = wusb_port_by_idx(wusbhc, idx);
  291. if ((port->status & USB_PORT_STAT_POWER)
  292. && !(port->status & USB_PORT_STAT_CONNECTION))
  293. break;
  294. }
  295. if (idx >= wusbhc->ports_max) {
  296. dev_err(dev, "Host controller can't connect more devices "
  297. "(%u already connected); device %s rejected\n",
  298. wusbhc->ports_max, pr_cdid);
  299. /* NOTE: we could send a WUIE_Disconnect here, but we haven't
  300. * event acked, so the device will eventually timeout the
  301. * connection, right? */
  302. goto error_unlock;
  303. }
  304. devnum = idx + 2;
  305. /* Make sure we are using no crypto on that "virtual port" */
  306. wusbhc->set_ptk(wusbhc, idx, 0, NULL, 0);
  307. /* Grab a filled in Connect-Ack context, fill out the
  308. * Connect-Ack Wireless USB IE, set the MMC */
  309. wusb_dev = wusbhc_cack_add(wusbhc, dnc, pr_cdid, idx);
  310. if (wusb_dev == NULL)
  311. goto error_unlock;
  312. result = wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr);
  313. if (result < 0)
  314. goto error_unlock;
  315. /* Give the device at least 2ms (WUSB1.0[7.5.1p3]), let's do
  316. * three for a good measure */
  317. msleep(3);
  318. port->wusb_dev = wusb_dev;
  319. port->status |= USB_PORT_STAT_CONNECTION;
  320. port->change |= USB_PORT_STAT_C_CONNECTION;
  321. /* Now the port status changed to connected; khubd will
  322. * pick the change up and try to reset the port to bring it to
  323. * the enabled state--so this process returns up to the stack
  324. * and it calls back into wusbhc_rh_port_reset().
  325. */
  326. error_unlock:
  327. mutex_unlock(&wusbhc->mutex);
  328. return;
  329. }
  330. /*
  331. * Disconnect a Wireless USB device from its fake port
  332. *
  333. * Marks the port as disconnected so that khubd can pick up the change
  334. * and drops our knowledge about the device.
  335. *
  336. * Assumes there is a device connected
  337. *
  338. * @port_index: zero based port number
  339. *
  340. * NOTE: @wusbhc->mutex is locked
  341. *
  342. * WARNING: From here it is not very safe to access anything hanging off
  343. * wusb_dev
  344. */
  345. static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
  346. struct wusb_port *port)
  347. {
  348. struct wusb_dev *wusb_dev = port->wusb_dev;
  349. port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE
  350. | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET
  351. | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
  352. port->change |= USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE;
  353. if (wusb_dev) {
  354. dev_dbg(wusbhc->dev, "disconnecting device from port %d\n", wusb_dev->port_idx);
  355. if (!list_empty(&wusb_dev->cack_node))
  356. list_del_init(&wusb_dev->cack_node);
  357. /* For the one in cack_add() */
  358. wusb_dev_put(wusb_dev);
  359. }
  360. port->wusb_dev = NULL;
  361. /* After a device disconnects, change the GTK (see [WUSB]
  362. * section 6.2.11.2). */
  363. wusbhc_gtk_rekey(wusbhc);
  364. /* The Wireless USB part has forgotten about the device already; now
  365. * khubd's timer will pick up the disconnection and remove the USB
  366. * device from the system
  367. */
  368. }
  369. /*
  370. * Refresh the list of keep alives to emit in the MMC
  371. *
  372. * Some devices don't respond to keep alives unless they've been
  373. * authenticated, so skip unauthenticated devices.
  374. *
  375. * We only publish the first four devices that have a coming timeout
  376. * condition. Then when we are done processing those, we go for the
  377. * next ones. We ignore the ones that have timed out already (they'll
  378. * be purged).
  379. *
  380. * This might cause the first devices to timeout the last devices in
  381. * the port array...FIXME: come up with a better algorithm?
  382. *
  383. * Note we can't do much about MMC's ops errors; we hope next refresh
  384. * will kind of handle it.
  385. *
  386. * NOTE: @wusbhc->mutex is locked
  387. */
  388. static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
  389. {
  390. struct device *dev = wusbhc->dev;
  391. unsigned cnt;
  392. struct wusb_dev *wusb_dev;
  393. struct wusb_port *wusb_port;
  394. struct wuie_keep_alive *ie = &wusbhc->keep_alive_ie;
  395. unsigned keep_alives, old_keep_alives;
  396. old_keep_alives = ie->hdr.bLength - sizeof(ie->hdr);
  397. keep_alives = 0;
  398. for (cnt = 0;
  399. keep_alives <= WUIE_ELT_MAX && cnt < wusbhc->ports_max;
  400. cnt++) {
  401. unsigned tt = msecs_to_jiffies(wusbhc->trust_timeout);
  402. wusb_port = wusb_port_by_idx(wusbhc, cnt);
  403. wusb_dev = wusb_port->wusb_dev;
  404. if (wusb_dev == NULL)
  405. continue;
  406. if (wusb_dev->usb_dev == NULL || !wusb_dev->usb_dev->authenticated)
  407. continue;
  408. if (time_after(jiffies, wusb_dev->entry_ts + tt)) {
  409. dev_err(dev, "KEEPALIVE: device %u timed out\n",
  410. wusb_dev->addr);
  411. __wusbhc_dev_disconnect(wusbhc, wusb_port);
  412. } else if (time_after(jiffies, wusb_dev->entry_ts + tt/2)) {
  413. /* Approaching timeout cut out, need to refresh */
  414. ie->bDeviceAddress[keep_alives++] = wusb_dev->addr;
  415. }
  416. }
  417. if (keep_alives & 0x1) /* pad to even number ([WUSB] section 7.5.9) */
  418. ie->bDeviceAddress[keep_alives++] = 0x7f;
  419. ie->hdr.bLength = sizeof(ie->hdr) +
  420. keep_alives*sizeof(ie->bDeviceAddress[0]);
  421. if (keep_alives > 0)
  422. wusbhc_mmcie_set(wusbhc, 10, 5, &ie->hdr);
  423. else if (old_keep_alives != 0)
  424. wusbhc_mmcie_rm(wusbhc, &ie->hdr);
  425. }
  426. /*
  427. * Do a run through all devices checking for timeouts
  428. */
  429. static void wusbhc_keep_alive_run(struct work_struct *ws)
  430. {
  431. struct delayed_work *dw = container_of(ws, struct delayed_work, work);
  432. struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer);
  433. mutex_lock(&wusbhc->mutex);
  434. __wusbhc_keep_alive(wusbhc);
  435. mutex_unlock(&wusbhc->mutex);
  436. queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
  437. msecs_to_jiffies(wusbhc->trust_timeout / 2));
  438. }
  439. /*
  440. * Find the wusb_dev from its device address.
  441. *
  442. * The device can be found directly from the address (see
  443. * wusb_cack_add() for where the device address is set to port_idx
  444. * +2), except when the address is zero.
  445. */
  446. static struct wusb_dev *wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
  447. {
  448. int p;
  449. if (addr == 0xff) /* unconnected */
  450. return NULL;
  451. if (addr > 0) {
  452. int port = (addr & ~0x80) - 2;
  453. if (port < 0 || port >= wusbhc->ports_max)
  454. return NULL;
  455. return wusb_port_by_idx(wusbhc, port)->wusb_dev;
  456. }
  457. /* Look for the device with address 0. */
  458. for (p = 0; p < wusbhc->ports_max; p++) {
  459. struct wusb_dev *wusb_dev = wusb_port_by_idx(wusbhc, p)->wusb_dev;
  460. if (wusb_dev && wusb_dev->addr == addr)
  461. return wusb_dev;
  462. }
  463. return NULL;
  464. }
  465. /*
  466. * Handle a DN_Alive notification (WUSB1.0[7.6.1])
  467. *
  468. * This just updates the device activity timestamp and then refreshes
  469. * the keep alive IE.
  470. *
  471. * @wusbhc shall be referenced and unlocked
  472. */
  473. static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  474. {
  475. mutex_lock(&wusbhc->mutex);
  476. wusb_dev->entry_ts = jiffies;
  477. __wusbhc_keep_alive(wusbhc);
  478. mutex_unlock(&wusbhc->mutex);
  479. }
  480. /*
  481. * Handle a DN_Connect notification (WUSB1.0[7.6.1])
  482. *
  483. * @wusbhc
  484. * @pkt_hdr
  485. * @size: Size of the buffer where the notification resides; if the
  486. * notification data suggests there should be more data than
  487. * available, an error will be signaled and the whole buffer
  488. * consumed.
  489. *
  490. * @wusbhc->mutex shall be held
  491. */
  492. static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
  493. struct wusb_dn_hdr *dn_hdr,
  494. size_t size)
  495. {
  496. struct device *dev = wusbhc->dev;
  497. struct wusb_dn_connect *dnc;
  498. char pr_cdid[WUSB_CKHDID_STRSIZE];
  499. static const char *beacon_behaviour[] = {
  500. "reserved",
  501. "self-beacon",
  502. "directed-beacon",
  503. "no-beacon"
  504. };
  505. if (size < sizeof(*dnc)) {
  506. dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n",
  507. size, sizeof(*dnc));
  508. return;
  509. }
  510. dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr);
  511. ckhdid_printf(pr_cdid, sizeof(pr_cdid), &dnc->CDID);
  512. dev_info(dev, "DN CONNECT: device %s @ %x (%s) wants to %s\n",
  513. pr_cdid,
  514. wusb_dn_connect_prev_dev_addr(dnc),
  515. beacon_behaviour[wusb_dn_connect_beacon_behavior(dnc)],
  516. wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect");
  517. /* ACK the connect */
  518. wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid);
  519. }
  520. /*
  521. * Handle a DN_Disconnect notification (WUSB1.0[7.6.1])
  522. *
  523. * Device is going down -- do the disconnect.
  524. *
  525. * @wusbhc shall be referenced and unlocked
  526. */
  527. static void wusbhc_handle_dn_disconnect(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  528. {
  529. struct device *dev = wusbhc->dev;
  530. dev_info(dev, "DN DISCONNECT: device 0x%02x going down\n", wusb_dev->addr);
  531. mutex_lock(&wusbhc->mutex);
  532. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, wusb_dev->port_idx));
  533. mutex_unlock(&wusbhc->mutex);
  534. }
  535. /*
  536. * Handle a Device Notification coming a host
  537. *
  538. * The Device Notification comes from a host (HWA, DWA or WHCI)
  539. * wrapped in a set of headers. Somebody else has peeled off those
  540. * headers for us and we just get one Device Notifications.
  541. *
  542. * Invalid DNs (e.g., too short) are discarded.
  543. *
  544. * @wusbhc shall be referenced
  545. *
  546. * FIXMES:
  547. * - implement priorities as in WUSB1.0[Table 7-55]?
  548. */
  549. void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
  550. struct wusb_dn_hdr *dn_hdr, size_t size)
  551. {
  552. struct device *dev = wusbhc->dev;
  553. struct wusb_dev *wusb_dev;
  554. if (size < sizeof(struct wusb_dn_hdr)) {
  555. dev_err(dev, "DN data shorter than DN header (%d < %d)\n",
  556. (int)size, (int)sizeof(struct wusb_dn_hdr));
  557. return;
  558. }
  559. wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr);
  560. if (wusb_dev == NULL && dn_hdr->bType != WUSB_DN_CONNECT) {
  561. dev_dbg(dev, "ignoring DN %d from unconnected device %02x\n",
  562. dn_hdr->bType, srcaddr);
  563. return;
  564. }
  565. switch (dn_hdr->bType) {
  566. case WUSB_DN_CONNECT:
  567. wusbhc_handle_dn_connect(wusbhc, dn_hdr, size);
  568. break;
  569. case WUSB_DN_ALIVE:
  570. wusbhc_handle_dn_alive(wusbhc, wusb_dev);
  571. break;
  572. case WUSB_DN_DISCONNECT:
  573. wusbhc_handle_dn_disconnect(wusbhc, wusb_dev);
  574. break;
  575. case WUSB_DN_MASAVAILCHANGED:
  576. case WUSB_DN_RWAKE:
  577. case WUSB_DN_SLEEP:
  578. /* FIXME: handle these DNs. */
  579. break;
  580. case WUSB_DN_EPRDY:
  581. /* The hardware handles these. */
  582. break;
  583. default:
  584. dev_warn(dev, "unknown DN %u (%d octets) from %u\n",
  585. dn_hdr->bType, (int)size, srcaddr);
  586. }
  587. }
  588. EXPORT_SYMBOL_GPL(wusbhc_handle_dn);
  589. /*
  590. * Disconnect a WUSB device from a the cluster
  591. *
  592. * @wusbhc
  593. * @port Fake port where the device is (wusbhc index, not USB port number).
  594. *
  595. * In Wireless USB, a disconnect is basically telling the device he is
  596. * being disconnected and forgetting about him.
  597. *
  598. * We send the device a Device Disconnect IE (WUSB1.0[7.5.11]) for 100
  599. * ms and then keep going.
  600. *
  601. * We don't do much in case of error; we always pretend we disabled
  602. * the port and disconnected the device. If physically the request
  603. * didn't get there (many things can fail in the way there), the stack
  604. * will reject the device's communication attempts.
  605. *
  606. * @wusbhc should be refcounted and locked
  607. */
  608. void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port_idx)
  609. {
  610. int result;
  611. struct device *dev = wusbhc->dev;
  612. struct wusb_dev *wusb_dev;
  613. struct wuie_disconnect *ie;
  614. wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
  615. if (wusb_dev == NULL) {
  616. /* reset no device? ignore */
  617. dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n",
  618. port_idx);
  619. return;
  620. }
  621. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
  622. ie = kzalloc(sizeof(*ie), GFP_KERNEL);
  623. if (ie == NULL)
  624. return;
  625. ie->hdr.bLength = sizeof(*ie);
  626. ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT;
  627. ie->bDeviceAddress = wusb_dev->addr;
  628. result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr);
  629. if (result < 0)
  630. dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result);
  631. else {
  632. /* At least 6 MMCs, assuming at least 1 MMC per zone. */
  633. msleep(7*4);
  634. wusbhc_mmcie_rm(wusbhc, &ie->hdr);
  635. }
  636. kfree(ie);
  637. }
  638. /*
  639. * Walk over the BOS descriptor, verify and grok it
  640. *
  641. * @usb_dev: referenced
  642. * @wusb_dev: referenced and unlocked
  643. *
  644. * The BOS descriptor is defined at WUSB1.0[7.4.1], and it defines a
  645. * "flexible" way to wrap all kinds of descriptors inside an standard
  646. * descriptor (wonder why they didn't use normal descriptors,
  647. * btw). Not like they lack code.
  648. *
  649. * At the end we go to look for the WUSB Device Capabilities
  650. * (WUSB1.0[7.4.1.1]) that is wrapped in a device capability descriptor
  651. * that is part of the BOS descriptor set. That tells us what does the
  652. * device support (dual role, beacon type, UWB PHY rates).
  653. */
  654. static int wusb_dev_bos_grok(struct usb_device *usb_dev,
  655. struct wusb_dev *wusb_dev,
  656. struct usb_bos_descriptor *bos, size_t desc_size)
  657. {
  658. ssize_t result;
  659. struct device *dev = &usb_dev->dev;
  660. void *itr, *top;
  661. /* Walk over BOS capabilities, verify them */
  662. itr = (void *)bos + sizeof(*bos);
  663. top = itr + desc_size - sizeof(*bos);
  664. while (itr < top) {
  665. struct usb_dev_cap_header *cap_hdr = itr;
  666. size_t cap_size;
  667. u8 cap_type;
  668. if (top - itr < sizeof(*cap_hdr)) {
  669. dev_err(dev, "Device BUG? premature end of BOS header "
  670. "data [offset 0x%02x]: only %zu bytes left\n",
  671. (int)(itr - (void *)bos), top - itr);
  672. result = -ENOSPC;
  673. goto error_bad_cap;
  674. }
  675. cap_size = cap_hdr->bLength;
  676. cap_type = cap_hdr->bDevCapabilityType;
  677. if (cap_size == 0)
  678. break;
  679. if (cap_size > top - itr) {
  680. dev_err(dev, "Device BUG? premature end of BOS data "
  681. "[offset 0x%02x cap %02x %zu bytes]: "
  682. "only %zu bytes left\n",
  683. (int)(itr - (void *)bos),
  684. cap_type, cap_size, top - itr);
  685. result = -EBADF;
  686. goto error_bad_cap;
  687. }
  688. switch (cap_type) {
  689. case USB_CAP_TYPE_WIRELESS_USB:
  690. if (cap_size != sizeof(*wusb_dev->wusb_cap_descr))
  691. dev_err(dev, "Device BUG? WUSB Capability "
  692. "descriptor is %zu bytes vs %zu "
  693. "needed\n", cap_size,
  694. sizeof(*wusb_dev->wusb_cap_descr));
  695. else
  696. wusb_dev->wusb_cap_descr = itr;
  697. break;
  698. default:
  699. dev_err(dev, "BUG? Unknown BOS capability 0x%02x "
  700. "(%zu bytes) at offset 0x%02x\n", cap_type,
  701. cap_size, (int)(itr - (void *)bos));
  702. }
  703. itr += cap_size;
  704. }
  705. result = 0;
  706. error_bad_cap:
  707. return result;
  708. }
  709. /*
  710. * Add information from the BOS descriptors to the device
  711. *
  712. * @usb_dev: referenced
  713. * @wusb_dev: referenced and unlocked
  714. *
  715. * So what we do is we alloc a space for the BOS descriptor of 64
  716. * bytes; read the first four bytes which include the wTotalLength
  717. * field (WUSB1.0[T7-26]) and if it fits in those 64 bytes, read the
  718. * whole thing. If not we realloc to that size.
  719. *
  720. * Then we call the groking function, that will fill up
  721. * wusb_dev->wusb_cap_descr, which is what we'll need later on.
  722. */
  723. static int wusb_dev_bos_add(struct usb_device *usb_dev,
  724. struct wusb_dev *wusb_dev)
  725. {
  726. ssize_t result;
  727. struct device *dev = &usb_dev->dev;
  728. struct usb_bos_descriptor *bos;
  729. size_t alloc_size = 32, desc_size = 4;
  730. bos = kmalloc(alloc_size, GFP_KERNEL);
  731. if (bos == NULL)
  732. return -ENOMEM;
  733. result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size);
  734. if (result < 4) {
  735. dev_err(dev, "Can't get BOS descriptor or too short: %zd\n",
  736. result);
  737. goto error_get_descriptor;
  738. }
  739. desc_size = le16_to_cpu(bos->wTotalLength);
  740. if (desc_size >= alloc_size) {
  741. kfree(bos);
  742. alloc_size = desc_size;
  743. bos = kmalloc(alloc_size, GFP_KERNEL);
  744. if (bos == NULL)
  745. return -ENOMEM;
  746. }
  747. result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size);
  748. if (result < 0 || result != desc_size) {
  749. dev_err(dev, "Can't get BOS descriptor or too short (need "
  750. "%zu bytes): %zd\n", desc_size, result);
  751. goto error_get_descriptor;
  752. }
  753. if (result < sizeof(*bos)
  754. || le16_to_cpu(bos->wTotalLength) != desc_size) {
  755. dev_err(dev, "Can't get BOS descriptor or too short (need "
  756. "%zu bytes): %zd\n", desc_size, result);
  757. goto error_get_descriptor;
  758. }
  759. result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result);
  760. if (result < 0)
  761. goto error_bad_bos;
  762. wusb_dev->bos = bos;
  763. return 0;
  764. error_bad_bos:
  765. error_get_descriptor:
  766. kfree(bos);
  767. wusb_dev->wusb_cap_descr = NULL;
  768. return result;
  769. }
  770. static void wusb_dev_bos_rm(struct wusb_dev *wusb_dev)
  771. {
  772. kfree(wusb_dev->bos);
  773. wusb_dev->wusb_cap_descr = NULL;
  774. };
  775. static struct usb_wireless_cap_descriptor wusb_cap_descr_default = {
  776. .bLength = sizeof(wusb_cap_descr_default),
  777. .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
  778. .bDevCapabilityType = USB_CAP_TYPE_WIRELESS_USB,
  779. .bmAttributes = USB_WIRELESS_BEACON_NONE,
  780. .wPHYRates = cpu_to_le16(USB_WIRELESS_PHY_53),
  781. .bmTFITXPowerInfo = 0,
  782. .bmFFITXPowerInfo = 0,
  783. .bmBandGroup = cpu_to_le16(0x0001), /* WUSB1.0[7.4.1] bottom */
  784. .bReserved = 0
  785. };
  786. /*
  787. * USB stack's device addition Notifier Callback
  788. *
  789. * Called from drivers/usb/core/hub.c when a new device is added; we
  790. * use this hook to perform certain WUSB specific setup work on the
  791. * new device. As well, it is the first time we can connect the
  792. * wusb_dev and the usb_dev. So we note it down in wusb_dev and take a
  793. * reference that we'll drop.
  794. *
  795. * First we need to determine if the device is a WUSB device (else we
  796. * ignore it). For that we use the speed setting (USB_SPEED_VARIABLE)
  797. * [FIXME: maybe we'd need something more definitive]. If so, we track
  798. * it's usb_busd and from there, the WUSB HC.
  799. *
  800. * Because all WUSB HCs are contained in a 'struct wusbhc', voila, we
  801. * get the wusbhc for the device.
  802. *
  803. * We have a reference on @usb_dev (as we are called at the end of its
  804. * enumeration).
  805. *
  806. * NOTE: @usb_dev locked
  807. */
  808. static void wusb_dev_add_ncb(struct usb_device *usb_dev)
  809. {
  810. int result = 0;
  811. struct wusb_dev *wusb_dev;
  812. struct wusbhc *wusbhc;
  813. struct device *dev = &usb_dev->dev;
  814. u8 port_idx;
  815. if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
  816. return; /* skip non wusb and wusb RHs */
  817. wusbhc = wusbhc_get_by_usb_dev(usb_dev);
  818. if (wusbhc == NULL)
  819. goto error_nodev;
  820. mutex_lock(&wusbhc->mutex);
  821. wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev);
  822. port_idx = wusb_port_no_to_idx(usb_dev->portnum);
  823. mutex_unlock(&wusbhc->mutex);
  824. if (wusb_dev == NULL)
  825. goto error_nodev;
  826. wusb_dev->usb_dev = usb_get_dev(usb_dev);
  827. usb_dev->wusb_dev = wusb_dev_get(wusb_dev);
  828. result = wusb_dev_sec_add(wusbhc, usb_dev, wusb_dev);
  829. if (result < 0) {
  830. dev_err(dev, "Cannot enable security: %d\n", result);
  831. goto error_sec_add;
  832. }
  833. /* Now query the device for it's BOS and attach it to wusb_dev */
  834. result = wusb_dev_bos_add(usb_dev, wusb_dev);
  835. if (result < 0) {
  836. dev_err(dev, "Cannot get BOS descriptors: %d\n", result);
  837. goto error_bos_add;
  838. }
  839. result = wusb_dev_sysfs_add(wusbhc, usb_dev, wusb_dev);
  840. if (result < 0)
  841. goto error_add_sysfs;
  842. out:
  843. wusb_dev_put(wusb_dev);
  844. wusbhc_put(wusbhc);
  845. error_nodev:
  846. return;
  847. wusb_dev_sysfs_rm(wusb_dev);
  848. error_add_sysfs:
  849. wusb_dev_bos_rm(wusb_dev);
  850. error_bos_add:
  851. wusb_dev_sec_rm(wusb_dev);
  852. error_sec_add:
  853. mutex_lock(&wusbhc->mutex);
  854. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
  855. mutex_unlock(&wusbhc->mutex);
  856. goto out;
  857. }
  858. /*
  859. * Undo all the steps done at connection by the notifier callback
  860. *
  861. * NOTE: @usb_dev locked
  862. */
  863. static void wusb_dev_rm_ncb(struct usb_device *usb_dev)
  864. {
  865. struct wusb_dev *wusb_dev = usb_dev->wusb_dev;
  866. if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
  867. return; /* skip non wusb and wusb RHs */
  868. wusb_dev_sysfs_rm(wusb_dev);
  869. wusb_dev_bos_rm(wusb_dev);
  870. wusb_dev_sec_rm(wusb_dev);
  871. wusb_dev->usb_dev = NULL;
  872. usb_dev->wusb_dev = NULL;
  873. wusb_dev_put(wusb_dev);
  874. usb_put_dev(usb_dev);
  875. }
  876. /*
  877. * Handle notifications from the USB stack (notifier call back)
  878. *
  879. * This is called when the USB stack does a
  880. * usb_{bus,device}_{add,remove}() so we can do WUSB specific
  881. * handling. It is called with [for the case of
  882. * USB_DEVICE_{ADD,REMOVE} with the usb_dev locked.
  883. */
  884. int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
  885. void *priv)
  886. {
  887. int result = NOTIFY_OK;
  888. switch (val) {
  889. case USB_DEVICE_ADD:
  890. wusb_dev_add_ncb(priv);
  891. break;
  892. case USB_DEVICE_REMOVE:
  893. wusb_dev_rm_ncb(priv);
  894. break;
  895. case USB_BUS_ADD:
  896. /* ignore (for now) */
  897. case USB_BUS_REMOVE:
  898. break;
  899. default:
  900. WARN_ON(1);
  901. result = NOTIFY_BAD;
  902. };
  903. return result;
  904. }
  905. /*
  906. * Return a referenced wusb_dev given a @wusbhc and @usb_dev
  907. */
  908. struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *wusbhc,
  909. struct usb_device *usb_dev)
  910. {
  911. struct wusb_dev *wusb_dev;
  912. u8 port_idx;
  913. port_idx = wusb_port_no_to_idx(usb_dev->portnum);
  914. BUG_ON(port_idx > wusbhc->ports_max);
  915. wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
  916. if (wusb_dev != NULL) /* ops, device is gone */
  917. wusb_dev_get(wusb_dev);
  918. return wusb_dev;
  919. }
  920. EXPORT_SYMBOL_GPL(__wusb_dev_get_by_usb_dev);
  921. void wusb_dev_destroy(struct kref *_wusb_dev)
  922. {
  923. struct wusb_dev *wusb_dev = container_of(_wusb_dev, struct wusb_dev, refcnt);
  924. list_del_init(&wusb_dev->cack_node);
  925. wusb_dev_free(wusb_dev);
  926. }
  927. EXPORT_SYMBOL_GPL(wusb_dev_destroy);
  928. /*
  929. * Create all the device connect handling infrastructure
  930. *
  931. * This is basically the device info array, Connect Acknowledgement
  932. * (cack) lists, keep-alive timers (and delayed work thread).
  933. */
  934. int wusbhc_devconnect_create(struct wusbhc *wusbhc)
  935. {
  936. wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE;
  937. wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr);
  938. INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run);
  939. wusbhc->cack_ie.hdr.bIEIdentifier = WUIE_ID_CONNECTACK;
  940. wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr);
  941. INIT_LIST_HEAD(&wusbhc->cack_list);
  942. return 0;
  943. }
  944. /*
  945. * Release all resources taken by the devconnect stuff
  946. */
  947. void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
  948. {
  949. /* no op */
  950. }
  951. /*
  952. * wusbhc_devconnect_start - start accepting device connections
  953. * @wusbhc: the WUSB HC
  954. *
  955. * Sets the Host Info IE to accept all new connections.
  956. *
  957. * FIXME: This also enables the keep alives but this is not necessary
  958. * until there are connected and authenticated devices.
  959. */
  960. int wusbhc_devconnect_start(struct wusbhc *wusbhc)
  961. {
  962. struct device *dev = wusbhc->dev;
  963. struct wuie_host_info *hi;
  964. int result;
  965. hi = kzalloc(sizeof(*hi), GFP_KERNEL);
  966. if (hi == NULL)
  967. return -ENOMEM;
  968. hi->hdr.bLength = sizeof(*hi);
  969. hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO;
  970. hi->attributes = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL);
  971. hi->CHID = wusbhc->chid;
  972. result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr);
  973. if (result < 0) {
  974. dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result);
  975. goto error_mmcie_set;
  976. }
  977. wusbhc->wuie_host_info = hi;
  978. queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
  979. (wusbhc->trust_timeout*CONFIG_HZ)/1000/2);
  980. return 0;
  981. error_mmcie_set:
  982. kfree(hi);
  983. return result;
  984. }
  985. /*
  986. * wusbhc_devconnect_stop - stop managing connected devices
  987. * @wusbhc: the WUSB HC
  988. *
  989. * Removes the Host Info IE and stops the keep alives.
  990. *
  991. * FIXME: should this disconnect all devices?
  992. */
  993. void wusbhc_devconnect_stop(struct wusbhc *wusbhc)
  994. {
  995. cancel_delayed_work_sync(&wusbhc->keep_alive_timer);
  996. WARN_ON(!list_empty(&wusbhc->cack_list));
  997. wusbhc_mmcie_rm(wusbhc, &wusbhc->wuie_host_info->hdr);
  998. kfree(wusbhc->wuie_host_info);
  999. wusbhc->wuie_host_info = NULL;
  1000. }
  1001. /*
  1002. * wusb_set_dev_addr - set the WUSB device address used by the host
  1003. * @wusbhc: the WUSB HC the device is connect to
  1004. * @wusb_dev: the WUSB device
  1005. * @addr: new device address
  1006. */
  1007. int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, u8 addr)
  1008. {
  1009. int result;
  1010. wusb_dev->addr = addr;
  1011. result = wusbhc->dev_info_set(wusbhc, wusb_dev);
  1012. if (result < 0)
  1013. dev_err(wusbhc->dev, "device %d: failed to set device "
  1014. "address\n", wusb_dev->port_idx);
  1015. else
  1016. dev_info(wusbhc->dev, "device %d: %s addr %u\n",
  1017. wusb_dev->port_idx,
  1018. (addr & WUSB_DEV_ADDR_UNAUTH) ? "unauth" : "auth",
  1019. wusb_dev->addr);
  1020. return result;
  1021. }