devconnect.c 33 KB

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