devconnect.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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. wusb_dev_put(wusb_dev);
  245. }
  246. /*
  247. * Ack a device for connection
  248. *
  249. * FIXME: docs
  250. *
  251. * @pr_cdid: Printable CDID...hex Use @dnc->cdid for the real deal.
  252. *
  253. * So we get the connect ack IE (may have been allocated already),
  254. * find an empty connect block, an empty virtual port, create an
  255. * address with it (see below), make it an unauth addr [bit 7 set] and
  256. * set the MMC.
  257. *
  258. * Addresses: because WUSB hosts have no downstream hubs, we can do a
  259. * 1:1 mapping between 'port number' and device
  260. * address. This simplifies many things, as during this
  261. * initial connect phase the USB stack has no knoledge of
  262. * the device and hasn't assigned an address yet--we know
  263. * USB's choose_address() will use the same euristics we
  264. * use here, so we can assume which address will be assigned.
  265. *
  266. * USB stack always assigns address 1 to the root hub, so
  267. * to the port number we add 2 (thus virtual port #0 is
  268. * addr #2).
  269. *
  270. * @wusbhc shall be referenced
  271. */
  272. static
  273. void wusbhc_devconnect_ack(struct wusbhc *wusbhc, struct wusb_dn_connect *dnc,
  274. const char *pr_cdid)
  275. {
  276. int result;
  277. struct device *dev = wusbhc->dev;
  278. struct wusb_dev *wusb_dev;
  279. struct wusb_port *port;
  280. unsigned idx, devnum;
  281. mutex_lock(&wusbhc->mutex);
  282. /* Check we are not handling it already */
  283. for (idx = 0; idx < wusbhc->ports_max; idx++) {
  284. port = wusb_port_by_idx(wusbhc, idx);
  285. if (port->wusb_dev
  286. && memcmp(&dnc->CDID, &port->wusb_dev->cdid, sizeof(dnc->CDID)) == 0)
  287. goto error_unlock;
  288. }
  289. /* Look up those fake ports we have for a free one */
  290. for (idx = 0; idx < wusbhc->ports_max; idx++) {
  291. port = wusb_port_by_idx(wusbhc, idx);
  292. if ((port->status & USB_PORT_STAT_POWER)
  293. && !(port->status & USB_PORT_STAT_CONNECTION))
  294. break;
  295. }
  296. if (idx >= wusbhc->ports_max) {
  297. dev_err(dev, "Host controller can't connect more devices "
  298. "(%u already connected); device %s rejected\n",
  299. wusbhc->ports_max, pr_cdid);
  300. /* NOTE: we could send a WUIE_Disconnect here, but we haven't
  301. * event acked, so the device will eventually timeout the
  302. * connection, right? */
  303. goto error_unlock;
  304. }
  305. devnum = idx + 2;
  306. /* Make sure we are using no crypto on that "virtual port" */
  307. wusbhc->set_ptk(wusbhc, idx, 0, NULL, 0);
  308. /* Grab a filled in Connect-Ack context, fill out the
  309. * Connect-Ack Wireless USB IE, set the MMC */
  310. wusb_dev = wusbhc_cack_add(wusbhc, dnc, pr_cdid, idx);
  311. if (wusb_dev == NULL)
  312. goto error_unlock;
  313. result = wusbhc_mmcie_set(wusbhc, 0, 0, &wusbhc->cack_ie.hdr);
  314. if (result < 0)
  315. goto error_unlock;
  316. /* Give the device at least 2ms (WUSB1.0[7.5.1p3]), let's do
  317. * three for a good measure */
  318. msleep(3);
  319. port->wusb_dev = wusb_dev;
  320. port->status |= USB_PORT_STAT_CONNECTION;
  321. port->change |= USB_PORT_STAT_C_CONNECTION;
  322. /* Now the port status changed to connected; khubd will
  323. * pick the change up and try to reset the port to bring it to
  324. * the enabled state--so this process returns up to the stack
  325. * and it calls back into wusbhc_rh_port_reset().
  326. */
  327. error_unlock:
  328. mutex_unlock(&wusbhc->mutex);
  329. return;
  330. }
  331. /*
  332. * Disconnect a Wireless USB device from its fake port
  333. *
  334. * Marks the port as disconnected so that khubd can pick up the change
  335. * and drops our knowledge about the device.
  336. *
  337. * Assumes there is a device connected
  338. *
  339. * @port_index: zero based port number
  340. *
  341. * NOTE: @wusbhc->mutex is locked
  342. *
  343. * WARNING: From here it is not very safe to access anything hanging off
  344. * wusb_dev
  345. */
  346. static void __wusbhc_dev_disconnect(struct wusbhc *wusbhc,
  347. struct wusb_port *port)
  348. {
  349. struct wusb_dev *wusb_dev = port->wusb_dev;
  350. port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE
  351. | USB_PORT_STAT_SUSPEND | USB_PORT_STAT_RESET
  352. | USB_PORT_STAT_LOW_SPEED | USB_PORT_STAT_HIGH_SPEED);
  353. port->change |= USB_PORT_STAT_C_CONNECTION | USB_PORT_STAT_C_ENABLE;
  354. if (wusb_dev) {
  355. dev_dbg(wusbhc->dev, "disconnecting device from port %d\n", wusb_dev->port_idx);
  356. if (!list_empty(&wusb_dev->cack_node))
  357. list_del_init(&wusb_dev->cack_node);
  358. /* For the one in cack_add() */
  359. wusb_dev_put(wusb_dev);
  360. }
  361. port->wusb_dev = NULL;
  362. /* After a device disconnects, change the GTK (see [WUSB]
  363. * section 6.2.11.2). */
  364. if (wusbhc->active)
  365. wusbhc_gtk_rekey(wusbhc);
  366. /* The Wireless USB part has forgotten about the device already; now
  367. * khubd's timer will pick up the disconnection and remove the USB
  368. * device from the system
  369. */
  370. }
  371. /*
  372. * Refresh the list of keep alives to emit in the MMC
  373. *
  374. * Some devices don't respond to keep alives unless they've been
  375. * authenticated, so skip unauthenticated devices.
  376. *
  377. * We only publish the first four devices that have a coming timeout
  378. * condition. Then when we are done processing those, we go for the
  379. * next ones. We ignore the ones that have timed out already (they'll
  380. * be purged).
  381. *
  382. * This might cause the first devices to timeout the last devices in
  383. * the port array...FIXME: come up with a better algorithm?
  384. *
  385. * Note we can't do much about MMC's ops errors; we hope next refresh
  386. * will kind of handle it.
  387. *
  388. * NOTE: @wusbhc->mutex is locked
  389. */
  390. static void __wusbhc_keep_alive(struct wusbhc *wusbhc)
  391. {
  392. struct device *dev = wusbhc->dev;
  393. unsigned cnt;
  394. struct wusb_dev *wusb_dev;
  395. struct wusb_port *wusb_port;
  396. struct wuie_keep_alive *ie = &wusbhc->keep_alive_ie;
  397. unsigned keep_alives, old_keep_alives;
  398. old_keep_alives = ie->hdr.bLength - sizeof(ie->hdr);
  399. keep_alives = 0;
  400. for (cnt = 0;
  401. keep_alives <= WUIE_ELT_MAX && cnt < wusbhc->ports_max;
  402. cnt++) {
  403. unsigned tt = msecs_to_jiffies(wusbhc->trust_timeout);
  404. wusb_port = wusb_port_by_idx(wusbhc, cnt);
  405. wusb_dev = wusb_port->wusb_dev;
  406. if (wusb_dev == NULL)
  407. continue;
  408. if (wusb_dev->usb_dev == NULL || !wusb_dev->usb_dev->authenticated)
  409. continue;
  410. if (time_after(jiffies, wusb_dev->entry_ts + tt)) {
  411. dev_err(dev, "KEEPALIVE: device %u timed out\n",
  412. wusb_dev->addr);
  413. __wusbhc_dev_disconnect(wusbhc, wusb_port);
  414. } else if (time_after(jiffies, wusb_dev->entry_ts + tt/2)) {
  415. /* Approaching timeout cut out, need to refresh */
  416. ie->bDeviceAddress[keep_alives++] = wusb_dev->addr;
  417. }
  418. }
  419. if (keep_alives & 0x1) /* pad to even number ([WUSB] section 7.5.9) */
  420. ie->bDeviceAddress[keep_alives++] = 0x7f;
  421. ie->hdr.bLength = sizeof(ie->hdr) +
  422. keep_alives*sizeof(ie->bDeviceAddress[0]);
  423. if (keep_alives > 0)
  424. wusbhc_mmcie_set(wusbhc, 10, 5, &ie->hdr);
  425. else if (old_keep_alives != 0)
  426. wusbhc_mmcie_rm(wusbhc, &ie->hdr);
  427. }
  428. /*
  429. * Do a run through all devices checking for timeouts
  430. */
  431. static void wusbhc_keep_alive_run(struct work_struct *ws)
  432. {
  433. struct delayed_work *dw = to_delayed_work(ws);
  434. struct wusbhc *wusbhc = container_of(dw, struct wusbhc, keep_alive_timer);
  435. mutex_lock(&wusbhc->mutex);
  436. __wusbhc_keep_alive(wusbhc);
  437. mutex_unlock(&wusbhc->mutex);
  438. queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
  439. msecs_to_jiffies(wusbhc->trust_timeout / 2));
  440. }
  441. /*
  442. * Find the wusb_dev from its device address.
  443. *
  444. * The device can be found directly from the address (see
  445. * wusb_cack_add() for where the device address is set to port_idx
  446. * +2), except when the address is zero.
  447. */
  448. static struct wusb_dev *wusbhc_find_dev_by_addr(struct wusbhc *wusbhc, u8 addr)
  449. {
  450. int p;
  451. if (addr == 0xff) /* unconnected */
  452. return NULL;
  453. if (addr > 0) {
  454. int port = (addr & ~0x80) - 2;
  455. if (port < 0 || port >= wusbhc->ports_max)
  456. return NULL;
  457. return wusb_port_by_idx(wusbhc, port)->wusb_dev;
  458. }
  459. /* Look for the device with address 0. */
  460. for (p = 0; p < wusbhc->ports_max; p++) {
  461. struct wusb_dev *wusb_dev = wusb_port_by_idx(wusbhc, p)->wusb_dev;
  462. if (wusb_dev && wusb_dev->addr == addr)
  463. return wusb_dev;
  464. }
  465. return NULL;
  466. }
  467. /*
  468. * Handle a DN_Alive notification (WUSB1.0[7.6.1])
  469. *
  470. * This just updates the device activity timestamp and then refreshes
  471. * the keep alive IE.
  472. *
  473. * @wusbhc shall be referenced and unlocked
  474. */
  475. static void wusbhc_handle_dn_alive(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  476. {
  477. mutex_lock(&wusbhc->mutex);
  478. wusb_dev->entry_ts = jiffies;
  479. __wusbhc_keep_alive(wusbhc);
  480. mutex_unlock(&wusbhc->mutex);
  481. }
  482. /*
  483. * Handle a DN_Connect notification (WUSB1.0[7.6.1])
  484. *
  485. * @wusbhc
  486. * @pkt_hdr
  487. * @size: Size of the buffer where the notification resides; if the
  488. * notification data suggests there should be more data than
  489. * available, an error will be signaled and the whole buffer
  490. * consumed.
  491. *
  492. * @wusbhc->mutex shall be held
  493. */
  494. static void wusbhc_handle_dn_connect(struct wusbhc *wusbhc,
  495. struct wusb_dn_hdr *dn_hdr,
  496. size_t size)
  497. {
  498. struct device *dev = wusbhc->dev;
  499. struct wusb_dn_connect *dnc;
  500. char pr_cdid[WUSB_CKHDID_STRSIZE];
  501. static const char *beacon_behaviour[] = {
  502. "reserved",
  503. "self-beacon",
  504. "directed-beacon",
  505. "no-beacon"
  506. };
  507. if (size < sizeof(*dnc)) {
  508. dev_err(dev, "DN CONNECT: short notification (%zu < %zu)\n",
  509. size, sizeof(*dnc));
  510. return;
  511. }
  512. dnc = container_of(dn_hdr, struct wusb_dn_connect, hdr);
  513. ckhdid_printf(pr_cdid, sizeof(pr_cdid), &dnc->CDID);
  514. dev_info(dev, "DN CONNECT: device %s @ %x (%s) wants to %s\n",
  515. pr_cdid,
  516. wusb_dn_connect_prev_dev_addr(dnc),
  517. beacon_behaviour[wusb_dn_connect_beacon_behavior(dnc)],
  518. wusb_dn_connect_new_connection(dnc) ? "connect" : "reconnect");
  519. /* ACK the connect */
  520. wusbhc_devconnect_ack(wusbhc, dnc, pr_cdid);
  521. }
  522. /*
  523. * Handle a DN_Disconnect notification (WUSB1.0[7.6.1])
  524. *
  525. * Device is going down -- do the disconnect.
  526. *
  527. * @wusbhc shall be referenced and unlocked
  528. */
  529. static void wusbhc_handle_dn_disconnect(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
  530. {
  531. struct device *dev = wusbhc->dev;
  532. dev_info(dev, "DN DISCONNECT: device 0x%02x going down\n", wusb_dev->addr);
  533. mutex_lock(&wusbhc->mutex);
  534. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, wusb_dev->port_idx));
  535. mutex_unlock(&wusbhc->mutex);
  536. }
  537. /*
  538. * Handle a Device Notification coming a host
  539. *
  540. * The Device Notification comes from a host (HWA, DWA or WHCI)
  541. * wrapped in a set of headers. Somebody else has peeled off those
  542. * headers for us and we just get one Device Notifications.
  543. *
  544. * Invalid DNs (e.g., too short) are discarded.
  545. *
  546. * @wusbhc shall be referenced
  547. *
  548. * FIXMES:
  549. * - implement priorities as in WUSB1.0[Table 7-55]?
  550. */
  551. void wusbhc_handle_dn(struct wusbhc *wusbhc, u8 srcaddr,
  552. struct wusb_dn_hdr *dn_hdr, size_t size)
  553. {
  554. struct device *dev = wusbhc->dev;
  555. struct wusb_dev *wusb_dev;
  556. if (size < sizeof(struct wusb_dn_hdr)) {
  557. dev_err(dev, "DN data shorter than DN header (%d < %d)\n",
  558. (int)size, (int)sizeof(struct wusb_dn_hdr));
  559. return;
  560. }
  561. wusb_dev = wusbhc_find_dev_by_addr(wusbhc, srcaddr);
  562. if (wusb_dev == NULL && dn_hdr->bType != WUSB_DN_CONNECT) {
  563. dev_dbg(dev, "ignoring DN %d from unconnected device %02x\n",
  564. dn_hdr->bType, srcaddr);
  565. return;
  566. }
  567. switch (dn_hdr->bType) {
  568. case WUSB_DN_CONNECT:
  569. wusbhc_handle_dn_connect(wusbhc, dn_hdr, size);
  570. break;
  571. case WUSB_DN_ALIVE:
  572. wusbhc_handle_dn_alive(wusbhc, wusb_dev);
  573. break;
  574. case WUSB_DN_DISCONNECT:
  575. wusbhc_handle_dn_disconnect(wusbhc, wusb_dev);
  576. break;
  577. case WUSB_DN_MASAVAILCHANGED:
  578. case WUSB_DN_RWAKE:
  579. case WUSB_DN_SLEEP:
  580. /* FIXME: handle these DNs. */
  581. break;
  582. case WUSB_DN_EPRDY:
  583. /* The hardware handles these. */
  584. break;
  585. default:
  586. dev_warn(dev, "unknown DN %u (%d octets) from %u\n",
  587. dn_hdr->bType, (int)size, srcaddr);
  588. }
  589. }
  590. EXPORT_SYMBOL_GPL(wusbhc_handle_dn);
  591. /*
  592. * Disconnect a WUSB device from a the cluster
  593. *
  594. * @wusbhc
  595. * @port Fake port where the device is (wusbhc index, not USB port number).
  596. *
  597. * In Wireless USB, a disconnect is basically telling the device he is
  598. * being disconnected and forgetting about him.
  599. *
  600. * We send the device a Device Disconnect IE (WUSB1.0[7.5.11]) for 100
  601. * ms and then keep going.
  602. *
  603. * We don't do much in case of error; we always pretend we disabled
  604. * the port and disconnected the device. If physically the request
  605. * didn't get there (many things can fail in the way there), the stack
  606. * will reject the device's communication attempts.
  607. *
  608. * @wusbhc should be refcounted and locked
  609. */
  610. void __wusbhc_dev_disable(struct wusbhc *wusbhc, u8 port_idx)
  611. {
  612. int result;
  613. struct device *dev = wusbhc->dev;
  614. struct wusb_dev *wusb_dev;
  615. struct wuie_disconnect *ie;
  616. wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
  617. if (wusb_dev == NULL) {
  618. /* reset no device? ignore */
  619. dev_dbg(dev, "DISCONNECT: no device at port %u, ignoring\n",
  620. port_idx);
  621. return;
  622. }
  623. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
  624. ie = kzalloc(sizeof(*ie), GFP_KERNEL);
  625. if (ie == NULL)
  626. return;
  627. ie->hdr.bLength = sizeof(*ie);
  628. ie->hdr.bIEIdentifier = WUIE_ID_DEVICE_DISCONNECT;
  629. ie->bDeviceAddress = wusb_dev->addr;
  630. result = wusbhc_mmcie_set(wusbhc, 0, 0, &ie->hdr);
  631. if (result < 0)
  632. dev_err(dev, "DISCONNECT: can't set MMC: %d\n", result);
  633. else {
  634. /* At least 6 MMCs, assuming at least 1 MMC per zone. */
  635. msleep(7*4);
  636. wusbhc_mmcie_rm(wusbhc, &ie->hdr);
  637. }
  638. kfree(ie);
  639. }
  640. /*
  641. * Walk over the BOS descriptor, verify and grok it
  642. *
  643. * @usb_dev: referenced
  644. * @wusb_dev: referenced and unlocked
  645. *
  646. * The BOS descriptor is defined at WUSB1.0[7.4.1], and it defines a
  647. * "flexible" way to wrap all kinds of descriptors inside an standard
  648. * descriptor (wonder why they didn't use normal descriptors,
  649. * btw). Not like they lack code.
  650. *
  651. * At the end we go to look for the WUSB Device Capabilities
  652. * (WUSB1.0[7.4.1.1]) that is wrapped in a device capability descriptor
  653. * that is part of the BOS descriptor set. That tells us what does the
  654. * device support (dual role, beacon type, UWB PHY rates).
  655. */
  656. static int wusb_dev_bos_grok(struct usb_device *usb_dev,
  657. struct wusb_dev *wusb_dev,
  658. struct usb_bos_descriptor *bos, size_t desc_size)
  659. {
  660. ssize_t result;
  661. struct device *dev = &usb_dev->dev;
  662. void *itr, *top;
  663. /* Walk over BOS capabilities, verify them */
  664. itr = (void *)bos + sizeof(*bos);
  665. top = itr + desc_size - sizeof(*bos);
  666. while (itr < top) {
  667. struct usb_dev_cap_header *cap_hdr = itr;
  668. size_t cap_size;
  669. u8 cap_type;
  670. if (top - itr < sizeof(*cap_hdr)) {
  671. dev_err(dev, "Device BUG? premature end of BOS header "
  672. "data [offset 0x%02x]: only %zu bytes left\n",
  673. (int)(itr - (void *)bos), top - itr);
  674. result = -ENOSPC;
  675. goto error_bad_cap;
  676. }
  677. cap_size = cap_hdr->bLength;
  678. cap_type = cap_hdr->bDevCapabilityType;
  679. if (cap_size == 0)
  680. break;
  681. if (cap_size > top - itr) {
  682. dev_err(dev, "Device BUG? premature end of BOS data "
  683. "[offset 0x%02x cap %02x %zu bytes]: "
  684. "only %zu bytes left\n",
  685. (int)(itr - (void *)bos),
  686. cap_type, cap_size, top - itr);
  687. result = -EBADF;
  688. goto error_bad_cap;
  689. }
  690. switch (cap_type) {
  691. case USB_CAP_TYPE_WIRELESS_USB:
  692. if (cap_size != sizeof(*wusb_dev->wusb_cap_descr))
  693. dev_err(dev, "Device BUG? WUSB Capability "
  694. "descriptor is %zu bytes vs %zu "
  695. "needed\n", cap_size,
  696. sizeof(*wusb_dev->wusb_cap_descr));
  697. else
  698. wusb_dev->wusb_cap_descr = itr;
  699. break;
  700. default:
  701. dev_err(dev, "BUG? Unknown BOS capability 0x%02x "
  702. "(%zu bytes) at offset 0x%02x\n", cap_type,
  703. cap_size, (int)(itr - (void *)bos));
  704. }
  705. itr += cap_size;
  706. }
  707. result = 0;
  708. error_bad_cap:
  709. return result;
  710. }
  711. /*
  712. * Add information from the BOS descriptors to the device
  713. *
  714. * @usb_dev: referenced
  715. * @wusb_dev: referenced and unlocked
  716. *
  717. * So what we do is we alloc a space for the BOS descriptor of 64
  718. * bytes; read the first four bytes which include the wTotalLength
  719. * field (WUSB1.0[T7-26]) and if it fits in those 64 bytes, read the
  720. * whole thing. If not we realloc to that size.
  721. *
  722. * Then we call the groking function, that will fill up
  723. * wusb_dev->wusb_cap_descr, which is what we'll need later on.
  724. */
  725. static int wusb_dev_bos_add(struct usb_device *usb_dev,
  726. struct wusb_dev *wusb_dev)
  727. {
  728. ssize_t result;
  729. struct device *dev = &usb_dev->dev;
  730. struct usb_bos_descriptor *bos;
  731. size_t alloc_size = 32, desc_size = 4;
  732. bos = kmalloc(alloc_size, GFP_KERNEL);
  733. if (bos == NULL)
  734. return -ENOMEM;
  735. result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size);
  736. if (result < 4) {
  737. dev_err(dev, "Can't get BOS descriptor or too short: %zd\n",
  738. result);
  739. goto error_get_descriptor;
  740. }
  741. desc_size = le16_to_cpu(bos->wTotalLength);
  742. if (desc_size >= alloc_size) {
  743. kfree(bos);
  744. alloc_size = desc_size;
  745. bos = kmalloc(alloc_size, GFP_KERNEL);
  746. if (bos == NULL)
  747. return -ENOMEM;
  748. }
  749. result = usb_get_descriptor(usb_dev, USB_DT_BOS, 0, bos, desc_size);
  750. if (result < 0 || result != desc_size) {
  751. dev_err(dev, "Can't get BOS descriptor or too short (need "
  752. "%zu bytes): %zd\n", desc_size, result);
  753. goto error_get_descriptor;
  754. }
  755. if (result < sizeof(*bos)
  756. || le16_to_cpu(bos->wTotalLength) != desc_size) {
  757. dev_err(dev, "Can't get BOS descriptor or too short (need "
  758. "%zu bytes): %zd\n", desc_size, result);
  759. goto error_get_descriptor;
  760. }
  761. result = wusb_dev_bos_grok(usb_dev, wusb_dev, bos, result);
  762. if (result < 0)
  763. goto error_bad_bos;
  764. wusb_dev->bos = bos;
  765. return 0;
  766. error_bad_bos:
  767. error_get_descriptor:
  768. kfree(bos);
  769. wusb_dev->wusb_cap_descr = NULL;
  770. return result;
  771. }
  772. static void wusb_dev_bos_rm(struct wusb_dev *wusb_dev)
  773. {
  774. kfree(wusb_dev->bos);
  775. wusb_dev->wusb_cap_descr = NULL;
  776. };
  777. static struct usb_wireless_cap_descriptor wusb_cap_descr_default = {
  778. .bLength = sizeof(wusb_cap_descr_default),
  779. .bDescriptorType = USB_DT_DEVICE_CAPABILITY,
  780. .bDevCapabilityType = USB_CAP_TYPE_WIRELESS_USB,
  781. .bmAttributes = USB_WIRELESS_BEACON_NONE,
  782. .wPHYRates = cpu_to_le16(USB_WIRELESS_PHY_53),
  783. .bmTFITXPowerInfo = 0,
  784. .bmFFITXPowerInfo = 0,
  785. .bmBandGroup = cpu_to_le16(0x0001), /* WUSB1.0[7.4.1] bottom */
  786. .bReserved = 0
  787. };
  788. /*
  789. * USB stack's device addition Notifier Callback
  790. *
  791. * Called from drivers/usb/core/hub.c when a new device is added; we
  792. * use this hook to perform certain WUSB specific setup work on the
  793. * new device. As well, it is the first time we can connect the
  794. * wusb_dev and the usb_dev. So we note it down in wusb_dev and take a
  795. * reference that we'll drop.
  796. *
  797. * First we need to determine if the device is a WUSB device (else we
  798. * ignore it). For that we use the speed setting (USB_SPEED_VARIABLE)
  799. * [FIXME: maybe we'd need something more definitive]. If so, we track
  800. * it's usb_busd and from there, the WUSB HC.
  801. *
  802. * Because all WUSB HCs are contained in a 'struct wusbhc', voila, we
  803. * get the wusbhc for the device.
  804. *
  805. * We have a reference on @usb_dev (as we are called at the end of its
  806. * enumeration).
  807. *
  808. * NOTE: @usb_dev locked
  809. */
  810. static void wusb_dev_add_ncb(struct usb_device *usb_dev)
  811. {
  812. int result = 0;
  813. struct wusb_dev *wusb_dev;
  814. struct wusbhc *wusbhc;
  815. struct device *dev = &usb_dev->dev;
  816. u8 port_idx;
  817. if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
  818. return; /* skip non wusb and wusb RHs */
  819. usb_set_device_state(usb_dev, USB_STATE_UNAUTHENTICATED);
  820. wusbhc = wusbhc_get_by_usb_dev(usb_dev);
  821. if (wusbhc == NULL)
  822. goto error_nodev;
  823. mutex_lock(&wusbhc->mutex);
  824. wusb_dev = __wusb_dev_get_by_usb_dev(wusbhc, usb_dev);
  825. port_idx = wusb_port_no_to_idx(usb_dev->portnum);
  826. mutex_unlock(&wusbhc->mutex);
  827. if (wusb_dev == NULL)
  828. goto error_nodev;
  829. wusb_dev->usb_dev = usb_get_dev(usb_dev);
  830. usb_dev->wusb_dev = wusb_dev_get(wusb_dev);
  831. result = wusb_dev_sec_add(wusbhc, usb_dev, wusb_dev);
  832. if (result < 0) {
  833. dev_err(dev, "Cannot enable security: %d\n", result);
  834. goto error_sec_add;
  835. }
  836. /* Now query the device for it's BOS and attach it to wusb_dev */
  837. result = wusb_dev_bos_add(usb_dev, wusb_dev);
  838. if (result < 0) {
  839. dev_err(dev, "Cannot get BOS descriptors: %d\n", result);
  840. goto error_bos_add;
  841. }
  842. result = wusb_dev_sysfs_add(wusbhc, usb_dev, wusb_dev);
  843. if (result < 0)
  844. goto error_add_sysfs;
  845. out:
  846. wusb_dev_put(wusb_dev);
  847. wusbhc_put(wusbhc);
  848. error_nodev:
  849. return;
  850. wusb_dev_sysfs_rm(wusb_dev);
  851. error_add_sysfs:
  852. wusb_dev_bos_rm(wusb_dev);
  853. error_bos_add:
  854. wusb_dev_sec_rm(wusb_dev);
  855. error_sec_add:
  856. mutex_lock(&wusbhc->mutex);
  857. __wusbhc_dev_disconnect(wusbhc, wusb_port_by_idx(wusbhc, port_idx));
  858. mutex_unlock(&wusbhc->mutex);
  859. goto out;
  860. }
  861. /*
  862. * Undo all the steps done at connection by the notifier callback
  863. *
  864. * NOTE: @usb_dev locked
  865. */
  866. static void wusb_dev_rm_ncb(struct usb_device *usb_dev)
  867. {
  868. struct wusb_dev *wusb_dev = usb_dev->wusb_dev;
  869. if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
  870. return; /* skip non wusb and wusb RHs */
  871. wusb_dev_sysfs_rm(wusb_dev);
  872. wusb_dev_bos_rm(wusb_dev);
  873. wusb_dev_sec_rm(wusb_dev);
  874. wusb_dev->usb_dev = NULL;
  875. usb_dev->wusb_dev = NULL;
  876. wusb_dev_put(wusb_dev);
  877. usb_put_dev(usb_dev);
  878. }
  879. /*
  880. * Handle notifications from the USB stack (notifier call back)
  881. *
  882. * This is called when the USB stack does a
  883. * usb_{bus,device}_{add,remove}() so we can do WUSB specific
  884. * handling. It is called with [for the case of
  885. * USB_DEVICE_{ADD,REMOVE} with the usb_dev locked.
  886. */
  887. int wusb_usb_ncb(struct notifier_block *nb, unsigned long val,
  888. void *priv)
  889. {
  890. int result = NOTIFY_OK;
  891. switch (val) {
  892. case USB_DEVICE_ADD:
  893. wusb_dev_add_ncb(priv);
  894. break;
  895. case USB_DEVICE_REMOVE:
  896. wusb_dev_rm_ncb(priv);
  897. break;
  898. case USB_BUS_ADD:
  899. /* ignore (for now) */
  900. case USB_BUS_REMOVE:
  901. break;
  902. default:
  903. WARN_ON(1);
  904. result = NOTIFY_BAD;
  905. };
  906. return result;
  907. }
  908. /*
  909. * Return a referenced wusb_dev given a @wusbhc and @usb_dev
  910. */
  911. struct wusb_dev *__wusb_dev_get_by_usb_dev(struct wusbhc *wusbhc,
  912. struct usb_device *usb_dev)
  913. {
  914. struct wusb_dev *wusb_dev;
  915. u8 port_idx;
  916. port_idx = wusb_port_no_to_idx(usb_dev->portnum);
  917. BUG_ON(port_idx > wusbhc->ports_max);
  918. wusb_dev = wusb_port_by_idx(wusbhc, port_idx)->wusb_dev;
  919. if (wusb_dev != NULL) /* ops, device is gone */
  920. wusb_dev_get(wusb_dev);
  921. return wusb_dev;
  922. }
  923. EXPORT_SYMBOL_GPL(__wusb_dev_get_by_usb_dev);
  924. void wusb_dev_destroy(struct kref *_wusb_dev)
  925. {
  926. struct wusb_dev *wusb_dev = container_of(_wusb_dev, struct wusb_dev, refcnt);
  927. list_del_init(&wusb_dev->cack_node);
  928. wusb_dev_free(wusb_dev);
  929. }
  930. EXPORT_SYMBOL_GPL(wusb_dev_destroy);
  931. /*
  932. * Create all the device connect handling infrastructure
  933. *
  934. * This is basically the device info array, Connect Acknowledgement
  935. * (cack) lists, keep-alive timers (and delayed work thread).
  936. */
  937. int wusbhc_devconnect_create(struct wusbhc *wusbhc)
  938. {
  939. wusbhc->keep_alive_ie.hdr.bIEIdentifier = WUIE_ID_KEEP_ALIVE;
  940. wusbhc->keep_alive_ie.hdr.bLength = sizeof(wusbhc->keep_alive_ie.hdr);
  941. INIT_DELAYED_WORK(&wusbhc->keep_alive_timer, wusbhc_keep_alive_run);
  942. wusbhc->cack_ie.hdr.bIEIdentifier = WUIE_ID_CONNECTACK;
  943. wusbhc->cack_ie.hdr.bLength = sizeof(wusbhc->cack_ie.hdr);
  944. INIT_LIST_HEAD(&wusbhc->cack_list);
  945. return 0;
  946. }
  947. /*
  948. * Release all resources taken by the devconnect stuff
  949. */
  950. void wusbhc_devconnect_destroy(struct wusbhc *wusbhc)
  951. {
  952. /* no op */
  953. }
  954. /*
  955. * wusbhc_devconnect_start - start accepting device connections
  956. * @wusbhc: the WUSB HC
  957. *
  958. * Sets the Host Info IE to accept all new connections.
  959. *
  960. * FIXME: This also enables the keep alives but this is not necessary
  961. * until there are connected and authenticated devices.
  962. */
  963. int wusbhc_devconnect_start(struct wusbhc *wusbhc)
  964. {
  965. struct device *dev = wusbhc->dev;
  966. struct wuie_host_info *hi;
  967. int result;
  968. hi = kzalloc(sizeof(*hi), GFP_KERNEL);
  969. if (hi == NULL)
  970. return -ENOMEM;
  971. hi->hdr.bLength = sizeof(*hi);
  972. hi->hdr.bIEIdentifier = WUIE_ID_HOST_INFO;
  973. hi->attributes = cpu_to_le16((wusbhc->rsv->stream << 3) | WUIE_HI_CAP_ALL);
  974. hi->CHID = wusbhc->chid;
  975. result = wusbhc_mmcie_set(wusbhc, 0, 0, &hi->hdr);
  976. if (result < 0) {
  977. dev_err(dev, "Cannot add Host Info MMCIE: %d\n", result);
  978. goto error_mmcie_set;
  979. }
  980. wusbhc->wuie_host_info = hi;
  981. queue_delayed_work(wusbd, &wusbhc->keep_alive_timer,
  982. (wusbhc->trust_timeout*CONFIG_HZ)/1000/2);
  983. return 0;
  984. error_mmcie_set:
  985. kfree(hi);
  986. return result;
  987. }
  988. /*
  989. * wusbhc_devconnect_stop - stop managing connected devices
  990. * @wusbhc: the WUSB HC
  991. *
  992. * Disconnects any devices still connected, stops the keep alives and
  993. * removes the Host Info IE.
  994. */
  995. void wusbhc_devconnect_stop(struct wusbhc *wusbhc)
  996. {
  997. int i;
  998. mutex_lock(&wusbhc->mutex);
  999. for (i = 0; i < wusbhc->ports_max; i++) {
  1000. if (wusbhc->port[i].wusb_dev)
  1001. __wusbhc_dev_disconnect(wusbhc, &wusbhc->port[i]);
  1002. }
  1003. mutex_unlock(&wusbhc->mutex);
  1004. cancel_delayed_work_sync(&wusbhc->keep_alive_timer);
  1005. wusbhc_mmcie_rm(wusbhc, &wusbhc->wuie_host_info->hdr);
  1006. kfree(wusbhc->wuie_host_info);
  1007. wusbhc->wuie_host_info = NULL;
  1008. }
  1009. /*
  1010. * wusb_set_dev_addr - set the WUSB device address used by the host
  1011. * @wusbhc: the WUSB HC the device is connect to
  1012. * @wusb_dev: the WUSB device
  1013. * @addr: new device address
  1014. */
  1015. int wusb_set_dev_addr(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev, u8 addr)
  1016. {
  1017. int result;
  1018. wusb_dev->addr = addr;
  1019. result = wusbhc->dev_info_set(wusbhc, wusb_dev);
  1020. if (result < 0)
  1021. dev_err(wusbhc->dev, "device %d: failed to set device "
  1022. "address\n", wusb_dev->port_idx);
  1023. else
  1024. dev_info(wusbhc->dev, "device %d: %s addr %u\n",
  1025. wusb_dev->port_idx,
  1026. (addr & WUSB_DEV_ADDR_UNAUTH) ? "unauth" : "auth",
  1027. wusb_dev->addr);
  1028. return result;
  1029. }