devconnect.c 33 KB

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